When writing unit tests around classes, often each test will call the constructor for our class and provide dependencies as arguments. However, this introduces some coupling between the tests and the signature of the constructor, which can make it very difficult to change our constructor in future.
I’ve worked on a number of projects throughout my lifetime that have had something in common: they’re tools used internally in businesses and each business wants the tool rebranded slightly to match their site. In fact, they’ve got another thing in common: it’s always been a major pain to do.
Dependency Injection, often written as DI, is a great way to ensure your code is as reusable and as clean as possible. The main benefit, with the help of an “injection container”, is that you can switch modules out for other modules easily and in a single place.