3 ms·
That is all well and good until the day you need to it to return two different results depending on which context its running in. Relying on fixed global state
by hvidgaard 5y ago
That is all well and good until the day you need to it to return two different results depending on which context its running in.
Relying on fixed global state is asking for trouble down the line if it's something that will be evolved over time. DI makes such changes possible because you're injecting it with the constructors, while still allowing you to have a singleton DB managing class today.
Another major benefit for long term maintainability is the ability to see _all_ dependencies in the single constructor. It certainly makes writing tests simpler from unit tests to in memory integration tests.