Skip to main content
1 of 4
biziclop
  • 3.4k
  • 23
  • 22

There are two main reasons I can see.

  1. Readability. If every unit of code has everything it needs to work on either injected or passed in as a parameter, it's easy to look at the code and instantly see what it's doing. This gives you a locality of function, which also enables you to separate concerns better.
  2. Testability. For a typical unit test you want to set up your environment for many different scenarios and injection makes this very easy to implement.
biziclop
  • 3.4k
  • 23
  • 22