CKGrafico / inversify-props

Wrapper of Inversify to inject your dependencies in the components, made with TypeScript and compatible with Vue, React and other component libraries.
MIT License
85 stars 9 forks source link

How can I use this library using my own inversify container? #10

Closed cesalberca closed 4 years ago

cesalberca commented 4 years ago

Hey! Great utility library!

I would like to have my own container using inversify and somehow be able to tell inversify-props to hook up with an existing container. For instance:

import { Container } from 'inversify'
import { container as containerProps } from 'inversify-props'

export const TYPES = {
  WINDOW: Symbol.for('WINDOW')
}

const container = new Container()
container.bind<Window>(TYPES.WINDOW).toConstantValue(window)
containerProps.use(container) // Or something similar
export { container }

And then in the component:

export default class extends Component {
  @inject(TYPES.WINDOW) window: Window
}

Is this possible?

CKGrafico commented 4 years ago

Is not going to work because the library is using the internal container https://github.com/CKGrafico/inversify-props/blob/master/src/lib/helpers.ts#L59 but is a good feature

cesalberca commented 4 years ago

Thanks for answering! Yeah, I think it'll be a good enhancement 🙂

CKGrafico commented 4 years ago

Hello I just published a version 2.0.0-alpha2 if you want to check you will find the code in v2 branch https://github.com/CKGrafico/inversify-props/tree/v2

cesalberca commented 4 years ago

Thanks, I'll check it out!