I'm trying dagger and my current use case is represented by the code below. I tought Dagger would inject the objects recursively ut that doesn't seem to happen.
I'm getting null on top.inner
.
public static class Bottom {
}
/*
public static class Inner {
@Inject Bottom bottom;
}
*/
public static interface Inner {
public Bottom bottom();
public static class Implementation() {
@Inject Bottom bottom;
@Override public Bottom bottom() {
return bottom;
}
}
}
public static class Top {
@Inject Provider<Inner> inner;
}
@Module(injects = {DaggerTest.class, /* Top.class, Inner.class, */ Bottom.class})
public class AppModule {
@Provides public Bottom providesBottom() {
return new Bottom();
}
}
@Inject Top top;
@Test
public void testProviderInjection() {
ObjectGraph graph = ObjectGraph.create(new AppModule());
graph.inject(this);
Assert.assertNotNull("top", top);
Assert.assertNotNull("top.inner", top.inner);
Assert.assertNotNull("top.inner.get()", top.inner.get());
/* Assert.assertNotNull("top.inner.get().bottom", top.inner.get().bottom); */
Assert.assertNotNull("top.inner.get().bottom", top.inner.get().bottom());
}
I have no ideia if this is the desired behavior of Dagger but if it is can you suggest me possible way to do this whitout resorting to injection on every object.
EDIT I changed a little the use case. I forget a little detail :(.
Thanks