Hi all,
excuse me if I'm asking something that had already been asked (then just please give me some link), because I tried to google this question before writing this mail with no result.
I have problems with cyclic dependency injection when using SetterInjection which is kind of weird to me (examples in picocontainer documentation are about Constructor based injection)
Below I have very simple example demoing behavior I'm talking about (if you run it you'll have an AbstractInjector$CyclicDependencyException)
The question is simple - how can I solve the kind of situation when I really need cyclic dependencies (at least with setter based injection)?
import org.picocontainer.DefaultPicoContainer;
import org.picocontainer.MutablePicoContainer;
import org.picocontainer.injectors.SetterInjection;
import org.picocontainer.DefaultPicoContainer;
import org.picocontainer.MutablePicoContainer;
import org.picocontainer.injectors.SetterInjection;
public class PicoTest {
public static class One {
private Two two;
public void setTwo(Two two) {
this.two = two;
}
}
public static class Two {
private One one;
public void setOne(One one) {
this.one = one;
}
}
public static void main(String[] args) throws Exception {
MutablePicoContainer container = new DefaultPicoContainer(new SetterInjection());
container.addComponent(One.class);
container.addComponent(Two.class);
container.getComponent(One.class);
}
}
--
Best Regards,
Kuzminskyy Igor