Skip to main content
Question Protected by gnat
Became Hot Network Question
applying existing tag isntead of creating new one
Link
null
  • 3.8k
  • 1
  • 14
  • 21
edited title
Link
Hans
  • 572
  • 1
  • 4
  • 16

Is Dependency Injection useful when implementations are never expected to change?

Source Link
Hans
  • 572
  • 1
  • 4
  • 16

Dependency Injection when implementations are never expected to change

Dependecy Injection makes mostly sense when using interfaces, since one of DI's strengths is to switch out implementations. It also decouples classes, since the consumer of the dependency does not need to know implementation details.

On the other hand, creating interfaces for just about anything without the expecation of having a different implementation in the future is considered bad practice.

In my experience, implementations of, say, MailService or SqliteRepository never change. We also don't write tests. Making the use of interfaces obsolete and therefore, to a large part, dependecy injection.

Is the "sweet spot" for dependency injections just where you would expect to have a different implementation at some point, including mocks for testing?