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.

Required fields*

10
  • 5
    Constructor injection beats setter injection for only one reason... -- Not quite. Constructor injection is associated with immutable objects. Commented Apr 10, 2018 at 19:58
  • ahh but if you pass in a reference type and keep a reference to it, say a list, you can alter it from outside Commented Apr 10, 2018 at 20:01
  • Yes, I'm having that discussion below Mark Seeman's answer right now. (He's the author of "Dependency Injection in .NET," by the way. Good book.) Commented Apr 10, 2018 at 20:04
  • hmm I think my point is different, or rather that immutable construction requires value types, which is not usual for DI Commented Apr 10, 2018 at 20:12
  • True immutability in an object-oriented language is harder than most people think it is. You don't need to pass value types, but you do need to pass objects that are themselves immutable. Commented Apr 10, 2018 at 20:32