Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

4. Automated Dependency Injection > Automated DI gets around the need to ‘pass ...

Automated DI gets around the need to ‘pass the parcel’, but keeps code flexible

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.

Automated DI shifts the responsibility for fulfiling dependencies to a third party

Figure 4-1. Automated DI shifts the responsibility for fulfiling dependencies to a third party

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:


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial