thiagobustamante / typescript-ioc

A Lightweight annotation-based dependency injection container for typescript.
MIT License
526 stars 64 forks source link

Possibility to have a factory or bind an already created instance to a type? #16

Closed nolazybits closed 6 years ago

nolazybits commented 6 years ago

Just wondering if this is possible. Couldn't find an example anywhere.. Thanks

westinpigott commented 6 years ago

Doesn't having an already instantiated object bound to a type defeat the purpose? Just not sure on the use case.

If you want to do it, you can try something like this: (Not tested)

Container.bind(SomeType).provider({
       get: () => { return existingObject; }
});
nolazybits commented 6 years ago

Use case is when object creation is outside of my reach yet I want to be able to use it part of the DI. Regards