Criticism and disadvantages of dependency injection
Dependency injection (DI) is a well known and fashionable pattern. Most of engineers know its advantages, like: Making isolation in unit testing possible/easy Explicitly defining dependencies of a class Facilitating good design (single responsibility principle (SRP) for example) Enabling switching implementations quickly (DbLogger instead of ConsoleLogger for example) I reckon there's industry wide consensus that DI is a good, useful pattern. There's not too much criticism at the moment. Disadvantages which are mentioned in the community are usually minor. Some of them: Increased number of classes Creation of unnecessary interfaces Currently we discuss architecture design with my colleague. He's quite conservative, but open minded. He likes to question things, which I consider good, because many people in IT just copy the newest trend, repeat the advantages and in general don't think too much - don't analyse too deep. The things I'd like to ask are: Should we use dependency injection when we have just one implementation? Should we ban creating new objects except language/framework ones? Is injecting a single implementation bad idea (let's say we have just one implementation so we don't want to create "empty" interface) if we don't plan to unit test a particular class?

Dependency injection (DI) is a well known and fashionable pattern. Most of engineers know its advantages, like:
- Making isolation in unit testing possible/easy
- Explicitly defining dependencies of a class
- Facilitating good design (single responsibility principle (SRP) for example)
- Enabling switching implementations quickly (
DbLogger
instead ofConsoleLogger
for example)
I reckon there's industry wide consensus that DI is a good, useful pattern. There's not too much criticism at the moment. Disadvantages which are mentioned in the community are usually minor. Some of them:
- Increased number of classes
- Creation of unnecessary interfaces
Currently we discuss architecture design with my colleague. He's quite conservative, but open minded. He likes to question things, which I consider good, because many people in IT just copy the newest trend, repeat the advantages and in general don't think too much - don't analyse too deep.
The things I'd like to ask are:
- Should we use dependency injection when we have just one implementation?
- Should we ban creating new objects except language/framework ones?
- Is injecting a single implementation bad idea (let's say we have just one implementation so we don't want to create "empty" interface) if we don't plan to unit test a particular class?