Using dependency injection or not is a bit like the difference in C between using printf and using fprintf . Caller gains flexibility through choice. When the caller does not want flexibility (for example, if all the output from your program goes to stdout, never stderr or a file), flexibility is a sheer burden since the caller must always pass the same “correct” value.
If you see dependency injection as a net workload, it means that your callers are not actually using it.
Your points 1 and 3 say that "the calling code has less freedom to influence what happens," which is not always an advantage. The test code, in particular, benefits from dependency on injections, but there may also be situations where subscribers want flexibility for other reasons. Are you logging in with printf , or are you logging in by calling functions on a nested log?
Point 2 boils down to how you develop your APIs. Yes, if the original design needs to be changed, then using fixed hidden dependencies you can protect the API from reflecting this change. Sometimes you can maintain the old API with the default value of a new dependency and add a new method / constructor with an additional parameter somewhere.
All that is said, the standard libraries in the languages that I used do not require a huge number of dependency injections. Thus, you are not alone in thinking that your APIs are not needed, but I suspect that you can get more from this internally than you are now. For example, can you verify your network code without connecting to a remote computer? If not, consider whether this part of your test procedure will be simpler, faster, and give a more accurate diagnosis if you could.
source share