简体   繁体   English

Dagger 2 inject()包含一个依赖循环

[英]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但结果是一样的。

My problem was that I was using version 2.0 of Dagger where this was still an open issue . 我的问题是我使用的是Dagger的2.0版,这仍然是一个悬而未决的问题 Once I updated it to the current 2.1 version the problem was not present anymore. 一旦我将其更新到当前的2.1版本,问题就不再存在了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM