pombreda / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 1 forks source link

Do not fail on circular constructor/setter dependency #690

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
===
public static class A {
    private final B b;

    @Inject
    public A(B b) {
        this.b = b;
    }
}

public static class B {
    private A a;

    @Inject
    public void setA(A a) {
        this.a = a;
    }
}

public static void main(String[] args) {
    Guice.createInjector(new AbstractModule() {
        @Override
        protected void configure() { }
    }).getInstance(A.class);
}
===

guice reports error:

===
Tried proxying com.company.Temp$A to support a circular dependency, but it is 
not an interface
===

Proxy is not needed here: guice should just create "B" first, inject it into 
"A" constructor and then inject "A" into "B".

Original issue reported on code.google.com by stepan.k...@gmail.com on 7 Mar 2012 at 7:42