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