In today's team meeting, I learned an important that generally the constructor injection should be used as possible over setter injection.
- Historically the setter-injection camp come from spring, whereas constructor-injection camp are from pico-container and GUICE. ref
- constructor injection is the way to indicate the class design problem, like if you have multiple dependnecies (usually more than three dependencies), you should re-think about the class redesign ref
- More comprehensive article with bounce of refences ref
But in the team meeting, my teammate argues from the unit test perspective, which I dont think it makes too much sense, as we are using Spock to deal with the unit testing, and it can handle static or private fields pretty well.
But after several readings, I think the @Inject combined with public constructor is the way to go.
For setter injection, you need to think from Builder pattern perspective.