Now we will use a DI container called StructureMap to be the external component to resolve our dependencies.
In this recipe, we'll use another DI container, StructureMap. StructureMap is very well received by the community.
StructureMap is also very light, but it has almost every feature that you would expect from a complete DI container library.
We will create the object graph of our dependencies for our application.
To do that, we will create a ConfigureService
method that returns an IServiceProvider
type.
As in the first recipe, we will do the following:
- Inject the
ServiceProducts
class by using a constructor in theHomeController
of an ASP.NET MVC 6 application. - Create a class called Product.
- Create an interface called
IProductService.
- Create a class called
ProductService
. - Modify
HomeController
to add a constructor that will injectIProductService.
- Create an action method called Products in
HomeController
. - Create a view called
Products.cshtml
. - Now...