I think each module should take care of its binds AND instances.
Let's suppose you create nested injectors: parentInjector and innerInjector. In this example innerInjector have a
lazy singleton bind of Class1.
If you ask for Class1 for innerInjector or parentInjector, they should return the same instance, right?
Well, it's not happening like that. When the injectors are nested, the main injector make a copy of all the inner injectors to it's own binds, so when you ask to parentInjector and innerInjector the same bind, they return different instances.
Expected Behavior
The expected behavior was that the innerInjector would be able to create the instances for its binds and parentInjector would just ask it to do so.
What does this PR do
This PR makes each injector take care of it's own binds and instances.
When there are nested injectors, the injector find in its own binds at first and if the bind is not found then it ask to the inner injectors.
The problem
I think each module should take care of its binds AND instances.
Let's suppose you create nested injectors:
parentInjector
andinnerInjector
. In this exampleinnerInjector
have a lazy singleton bind ofClass1
.If you ask for
Class1
forinnerInjector
orparentInjector
, they should return the same instance, right?Well, it's not happening like that. When the injectors are nested, the main injector make a copy of all the inner injectors to it's own binds, so when you ask to
parentInjector
andinnerInjector
the same bind, they return different instances.Expected Behavior
The expected behavior was that the
innerInjector
would be able to create the instances for its binds andparentInjector
would just ask it to do so.What does this PR do
This PR makes each injector take care of it's own binds and instances. When there are nested injectors, the injector find in its own binds at first and if the bind is not found then it ask to the inner injectors.