Dependency Injection is a set of software design principles and patterns that enable you to develop loosely coupled code. Loose coupling makes code more maintainable.
When you have a loosely coupled infrastructure in place, it can be used by anyone and adapted to changing needs and unanticipated requirements without having to make large changes to the application’s code base and its infrastructure. Troubleshooting tends to become less taxing because the scope of likely culprits narrows.
DI enables late binding, which is the ability to replace classes or modules with different ones without the need for the original code to be recompiled. DI makes it easier for code to be extended and reused in ways not explicitly planned for, similar to the way you have flexibility when working with electrical plugs and sockets.