google / google/guice

Do not fail on circular constructor/setter dependency

Open
#690 1 comment 0 reactions 0 assignees View on GitHub
imported
Dominant language
Java
Stars
12.7k
Forks
1.7k
Avg merge
11m
Merged PRs (30d)
2

Description

_From [stepan.koltsov](https://code.google.com/u/113939464116033188989/) on March 07, 2012 14:42:18_
#

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: http://code.google.com/p/google-guice/issues/detail?id=690_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.