Hello!
I have the SSCCE code written below. Why can't I use requestInjection in a
module and have my object injected at the time of request? How do I
*actually* inject an object when I *know* all its dependencies have been
provided?
The problem I try to solve is that I need different implementations based
on properties. In a previous module, I bound those properties using
Names.bindProperties(). I will not create all the dependencies then chose
which one to use afterwards. Do I really need to pass my Properties around
the various modules?
Thanks.
Olivier
public class RequestInjectionTest {
@Test public void testRequestInjectionInModule() { // fails
Guice.createInjector(new AbstractModule() {
@Override protected void configure() {
final Holder holder = new Holder();
bind(String.class).annotatedWith(Names.named("value")).toInstance("value");
requestInjection(holder);
Assert.assertEquals("value", holder.value);
}
});
}
@Test public void testRequestInjectionOutsideOfModule() { //Succeeds
final Holder holder = new Holder();
Guice.createInjector(new AbstractModule() {
@Override protected void configure() {
bind(String.class).annotatedWith(Names.named("value")).toInstance("value");
requestInjection(holder);
}
});
Assert.assertEquals("value", holder.value);
}
public static class Holder {
@Inject @Named("value") public String value;
}
}
--
Olivier Grégoire
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.