Dependency injection is a special design pattern for software developed to implement control inversion and provide a program with the ability to follow the principle of dependency inversion. Spring, Glassfish HK2, Guice, Microsoft Managed Extensibility Framework and other application frameworks support dependency injection.
An injection is the passing of a service to a client (a dependency to a dependent object). The service is made part of the client’s state. The pattern is based on the next fundamental requirement: a service is passed to a client, instead of allowing a client to find the service. It separates the creation of client’s dependencies from its own behavior. As a result, program designs are loosely coupled and able to follow the single responsibility and dependency inversion principles. The opposite approach is implemented in the service locator pattern, which is designed to allow clients to get the information about the system used to find dependencies.