Open Deathrage opened 1 year ago
👍 We are encountering the same issue while migrating from typed-inject which provides this feature. Did you find a workaround @Deathrage?
@vhiairrassary yes
container.bind(Container).toDynamicValue(ctx => ctx.container as Container);
But this is somewhat a hack as ctx.container
is not class Container
but interface Container
and I cast it to the class (watchout, you cannot be sure that ctx.container
is an instance of that class as it might be a different subtype; However, as of now it is instnace of that class).
Thank you so much 🤩 Hopefully the feature will be implemented at some point in the project 🤞
Expected Behavior
Generally IoC container allow self injection. I will demonstrate in C#. This is to demonstrate that this approach is common and supported by other frameworks (example below demonstrate .NET Core's IoC container).
In this case, constructor recieve instance that is constructing given type. This means that child containers propagte their own instance.
Usecase in TypeScript:
Current Behavior
Uncaught Error: No matching bindings found for serviceIdentifier: Container at _validateActiveBindingCount (planner.js:59:1) at _getActiveBindings (planner.js:45:1) at _createSubRequests (planner.js:86:1) at planner.js:110:1 at Array.forEach ()
at planner.js:109:1
at Array.forEach ()
at _createSubRequests (planner.js:89:1)
at plan (planner.js:131:1)
at container.js:598:31
Your Environment