public class Widget {
@Inject
Fizz fizz;
public Widget(Fizz fizz) {
super();
setFizz(fizz);
}
public void setFizz(Fizz fizz) {
this.fizz = fizz;
}
}
Is this a Guice anti-pattern?!?!
If I say “fizz will be injected (via @Inject)”, but then I allow a constructor and setter to accept a fizz, is this unnecessarily-redundant? Could it cause a conflict with Guice’s injector?
I guess I’m confused as to:
- When you should annotate a property with
@Inject, vs. - When you should “inject” the property yourself via constructor/getter
Any thoughts? Thanks in advance!
Why not use something like this (i.e. use constructor injection) ?
See also http://code.google.com/p/google-guice/wiki/Injections