Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The intention behind automated DI containers is to abstract the fulfilment of dependencies from the application itself. Essentially, we split this job out completely, so that the application code no longer has to do it, and instead we ask a third party—the DI container—to get it done.
This reduction of responsibilities for your own code is a plus, but there’s another advantage: being able to type your dependencies against interfaces instead of concrete types.
A getInstance() singleton always requires you
to be dependent on a concrete class. For example, even if UserXMLLoader implements an
IUserLoader
interface, the XMLUserLoadingService has to use the actual
class, and not the interface, in order to access the static getInstance method: