How to do it...

We will inject the ServiceProducts class by using a constructor in the HomeController of an ASP.NET MVC 6 application:

  1. First, we create a class called Product:
  1. We then create an interface called IProductService:
  1. Next, we create a class called ProductService:
  1. Let's use ProductService in our HomeController, creating an instance of ProductService by injecting the ProductService abstraction in the HomeController constructor.  ...

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.