How it works...

Let's use ProductService in our HomeController to create an instance of ProductService by injecting the ProductService abstraction in the HomeController constructor.

ProductService will be available for the whole HomeController class.

We will use a module to help us to configure dependencies.

According to the Autofac documentation:

A module is a small class that can be used to bundle up a set of related components behind a 'facade' to simplify configuration and deployment. The module exposes a deliberate, restricted set of configuration parameters that can vary independently of the components used to implement the module.

Get ASP.NET Core MVC 2.0 Cookbook 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.