[英]Dagger 2 inject() contains a dependency cycle
I have the following setup in Dagger that I'm trying to migrate to Dagger 2: 我在Dagger中有以下设置,我正在尝试迁移到Dagger 2:
public class Origin {
final A a;
public Origin(A a) {
this.a = a;
}
}
public class A {
final B b;
@Inject public A (B b) {
this.b = b;
}
}
public class B {
final Lazy<A> a;
@Inject public B (Lazy<A> a) {
this.a = a;
}
}
Then on my module I have: 然后在我的模块上我有:
@Provides @Singleton Origin providesOrigin(A a) {
return new Origin(a);
}
Problem is, even though I'm using Lazy
, Dagger 2 gives me the following compile time error: 问题是,即使我使用
Lazy
,Dagger 2也会给出以下编译时错误:
error: AppComponent.inject() contains a dependency cycle
错误:AppComponent.inject()包含一个依赖循环
Am I missing something? 我错过了什么吗? I tried replacing
Lazy
with Provider
but the result is the same. 我尝试用提供
Provider
替换Lazy
但结果是一样的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.