7.2. Design

We can solve these problems by using an IoC Container that will be able to decide at run time which implementation of the interfaces to instantiate — this is where we invert the control and redirect the instantiation away from the dependent object. The container would then pass the correct instance into the dependent object's constructor; that is, it will inject the dependency.

Without an IoC Container, our class diagram would look like Figure 7-1.

Figure 7-1. Figure 7-1

If we use an IoC container, we will eliminate the dependency on the concrete implementation and remove the instantiation logic from the dependent class. Our class diagram would look like Figure 7-2.

Figure 7-2. Figure 7-2

Get ASP.NET MVC 1.0 Test Driven Development: Problem - Design - Solution now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.