vipx / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Parent injector is injected when using childinjector #714

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When creating a childinjector, the parentinjector is injected into the class 
instead of the childinjector.

Injector parent = Guice.createInjector();
Injector child = parent.createChildInjector();
Dao dao1 = parent.getInstance(Dao.class);
Dao dao2 = child.getInstance(Dao.class);

public static class Dao
{
@Inject
public Injector injector;
}

When calling the following code, the behaviour is correct.
Injector injector1 = parent.getInstance(Injector.class);
Injector injector2 = child.getInstance(Injector.class);

Original issue reported on code.google.com by timefre...@googlemail.com on 2 Jul 2012 at 1:22

GoogleCodeExporter commented 9 years ago
See https://groups.google.com/d/msg/google-guice/Q592mWKTS1Q/2Ovv0SzbjBwJ

This is working as designed, the injector that is injected is the one that 
defined the binding - in this case because  the binding for Dao.class is 
implicit (aka a just-in-time binding) it is bound in the parent injector and 
then inherited by the child (but the defining injector is still the parent).

Original comment by mccu...@gmail.com on 2 Jul 2012 at 1:30

GoogleCodeExporter commented 9 years ago

Original comment by sberlin on 2 Jul 2012 at 1:32