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*

5
  • 4
    "Constructor injection ... has no advantage over method injection" this is incorrect - it has the two advantages I listed in my answer: It forces variable initialization and potential detects cyclic dependencies (as you are unable to sequence the constructor calls if a cyclic dependency exists). Commented Apr 19, 2023 at 8:04
  • FWIW, you could also say method injection has the advantage of allowing cyclical dependencies, if you're into that sort of thing! Commented Apr 19, 2023 at 21:39
  • 1
    I do not encourage the method injection example provided here, especially when writer is shared. Commented Apr 20, 2023 at 8:03
  • @S.D. care to elaborate? Commented Apr 20, 2023 at 17:21
  • 1
    to @DavidT comment - constructor injection also addresses the general Inversion of Control (IOC) abstraction. Commented Apr 20, 2023 at 23:02