私は短剣を試していますが、現在のユースケースは以下のコードで表されています。私はダガーがオブジェクトを再帰的に注入すると思ったが、それは起こらないようだ.
で null になっています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());
}
これがダガーの望ましい動作であるかどうかはわかりませんが、そうである場合は、すべてのオブジェクトへの注入に頼らずにこれを行う方法を提案できます。
編集ユースケースを少し変更しました。ちょっと細かいことは忘れました(.
ありがとう