Guice: Child injector injecting root injector rather then itself

Created on 7 Jul 2014  ·  3Comments  ·  Source: google/guice

_From an.perez83 on April 15, 2010 06:54:44_

Hi everyone,

according to the JavaDoc of com.google.inject.Injector all injectors are supposed to have a binding
from Injector.class to themselves. Nevertheless, the child Injector seems to inject its root injector
rather then itself. I attached a short example code.

I guess that either the documentation or the implementation is faulty.

Cheers

Attachment: gist
   _child_injecting_parent.txt_

_Original issue: http://code.google.com/p/google-guice/issues/detail?id=472_

imported invalid

Most helpful comment

_From an.perez83 on April 15, 2010 04:04:34_

Alright, I figured out a workaround: one must bind the class into which the child injector is going to be
injected explicitly in he child injector's bindings. For my previous example, this would mean something like
this: bind(A.class);

Nevertheless, I consider the current behavior a bug.

All 3 comments

_From an.perez83 on April 15, 2010 04:04:34_

Alright, I figured out a workaround: one must bind the class into which the child injector is going to be
injected explicitly in he child injector's bindings. For my previous example, this would mean something like
this: bind(A.class);

Nevertheless, I consider the current behavior a bug.

_From sberlin on April 15, 2010 05:53:51_

This is because if the binding does not exist in the child injector's module, Guice
will create it as a "just in time" binding, and JIT bindings are created in the
parent modules (for a variety of reasons).

_From sberlin on April 25, 2010 15:17:14_

(No comment was entered for this change.)

Status: Invalid

Was this page helpful?
0 / 5 - 0 ratings

Related issues

scottcarey picture scottcarey  ·  17Comments

avoss picture avoss  ·  17Comments

nathanmerrill picture nathanmerrill  ·  5Comments

prasanthgithub picture prasanthgithub  ·  14Comments

jhm-ciberman picture jhm-ciberman  ·  10Comments