Dependency injection (DI) is a popular concept in software development. Two of its primary objectives are to achieve reusability and to simplify software maintenance and testing by coupling components loosely.
If an object A gives a reference to an object B, as a rule it knows its implementation. With the DI concept, the dependencies between the caller A and the objectives B it addresses are no longer stored in A. Which realisation of the target object B is to be specifically addressed is only notified to the caller if and when the need arises. The relationship to the specific B is then "injected" into A. Thus A as the caller doesn't know the target object that is to be used until the final injection.
DI is an application of the Inversion of Control (IoC) paradigm, also known as the Hollywood principle, "Don’t call us, we’ll call you". This way, dependency injection enables different usage scenarios to be employed, without any need to change the caller's source code, for example when new realisations of the target objects are added. A common example of such a further objective would be a simplified version of an original service, to be used for testing purposes. If the real service needs a lot of resources and takes a long time to run, or if indeed it is only available in the production environment, using the form of a mock (dummy) object permits (faster) testing.