In Chapter 3, you read about the principles of Dependency Inversion and Dependency Injection, and learned how objects collaborating together in modules can be built in a loosely coupled fashion by inverting the relationship of a dependent to its dependencies. However after moving the responsibility of creating the dependencies out of the service modules, you have been left with the problem of where and when the concrete implementations are created.
To demonstrate the problems of constructing objects with dependencies, let's consider a simple example of a service that requires two low-level detail objects.
TouristInformationService is a service that pinpoints places of interest on a map. The service requires a map and a dictionary of places of interest. The service has a single method,
FindInterestingPlacesNear, which takes a location object and returns a map filled with places of interest. The service has been designed in a loosely coupled fashion, via a Test Driven Design methodology and you have been very strict about not to tying yourself down to any concrete implementation. Figure 5-1 shows the class diagram of the
Figure 5-1. Figure 5-1
You will be using this sample code to demonstrate the concepts of Inversion of Control, so let's first build the sample.
Create a new blank solution ...