Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 26
    The reason for constructor injection is to make dependencies obvious, not because it looks more natural for java developers. Commented Mar 18, 2013 at 10:10
  • 8
    Late comment, but this answer made me laugh :) Commented Mar 13, 2014 at 15:03
  • 1
    +1 for setter based injections. If I have services and repositories defined in my class its pretty damn obvious they are dependencies.. I don't need to write massive VB6 looking constructors, and do stupid assigning code in the constructor. Its pretty obvious what the dependencies are on the fields required. Commented Apr 13, 2017 at 8:28
  • As per 2018, Spring officially recommends not using setter injection except for dependencies that have a reasonable default value. As in, if the dependency is mandatory to the class, constructor injection is recommended. See discussion on setter vs ctor DI Commented Dec 23, 2019 at 2:26