My understanding of Guice is that:
- Constructor-level injection (
@Inject public class Widget(Dep one, Dep two)) implies that Guice will always inject that constructor every time it is invoked through anInjector; and - Method-level injection (
@Inject public void setDepOne(Dep one)) implies that Guice will always inject that method whenever it is called, so long as theWidgetobject was created using the GuiceInjector
Are these two assumptions correct? If not, please clarify!
So what I'm hung up on is: what are the implications of field-level injection?
@Inject private Dep one;
Does this mean that Guice will always inject the property when the object is created through the Guice injector? In that case I would imagine it conflicts with constructor-level injection.
For instance, does the following cause a conflict/error:
public class Widget {
@Inject private Dep one;
private Dep two;
// Dep one already injected as a field!
@Inject public Widget(Dep one, Dep two) {
// ...
}
}
Thanks in advance!