I've heard it said many times that a benefit of using Dependency Injection (DI) is that it allows/encourages/enforces the Single Responsibility Principle (SRP). I question whether that is true and would appreciate clarification, which I have not been able to find.
In my mind, the use of dependencies allows for SRP, but how those dependencies are created, whether through instantiation, injection, or some other mechanism, does nothing for SRP directly. Can some one provide an example for how using DI, either through a constructor or properties, allows/encourages/enforces SRP any more so that having the same dependencies which are created in the type initializer or constructor?
There is an interesting paragraph in (my book) Dependency Injection Principles, Practices, and Patterns that talks about the relationship between DI and the SRP:
Some years back, with one of my clients, I came across a class that contained over 90 dependencies. Those were all injected as abstractions into the constructor, so Dependency Injection was practiced. With over 90 dependencies, however, its hard to argue that such class does not violate the SRP—and that class absolutely did.
Even though the developers used DI, they were able to create a monster class that violated the SRP big time. That basically proves your point: DI does not enforce, nor automatically lead to SRP. But, on the other hand, as the book states, a class with many constructor arguments is a good indication that the SRP is violated. DI does make SRP violations more obvious, because the dependencies are clearly declared in a class's constructor. In the book we use a heuristic of 4 or 5 dependencies. Has a class crosses that number, it's time to take a good look at that class and check whether it violates the SRP principle (or any other SOLID principle for that matter).