I have the following Guice module:
class MyModule extends AbstractModule { @Override protected void configure() { bindListener(Matchers.any(), new TypeListener() {...}); } @Provides SomeClass createSomeClass(final Parameter param) { log(param.getValue()); <-- this gets logged ... } }
What I found strange is that my TypeListener does not receive notification of type Parameter . Even if the provider is called beign and returns SomeClass . I also see the log report so clearly that Parameter was introduced by Guice.
@Override protected void configure() { bind(Parameter.class); bindListener(Matchers.any(), new TypeListener() {...}); }
I know Untargetted bindings and statement:
Unbound binding informs the injector about the type, so it can prepare dependencies with impatience.
I would still expect Guice to call TypeListener for any type that is either explicitly bound or injected for the first time.
So what do I need to do unmarketed binding for such classes as a rule?
NOTE. labeling the Parameter constructor with @Inject does not solve the problem.
EDIT:
A complete example (hope I don't leave too much garbage) looks like this:
public class TestGuice { public static void main(String[] args) { Injector parentInjector = Guice.createInjector(new ParentModule()); Injector childInjector = parentInjector.createChildInjector(new SubModule()); childInjector.getInstance(Runnable.class).run(); } static class ParentModule extends AbstractModule { @Override protected void configure() { } } static class SubModule extends AbstractModule { @Override protected void configure() { bind(SampleInjectedClass.class);
If a string is present, the output is:
Type: class com.barcap.test.TestGuice $ SampleInjectedClass
Type: class com.google.inject.internal.ProviderMethod
Test
If I delete the line, I get:
Type: class com.google.inject.internal.ProviderMethod
Test
I noticed that if the injector was not created using the createChildInjector code, bind(...) not required.