How to do it...

  1. First, let's add the AutoMapper dependency to project.json.
  2. After that, we will create the ProductRepository with fake data. Our HomeController controller class will consume the data from this repository. The objects consumed from the repository will be ProductDto objects, but we will use them only to transport data between the repository and the controller:
public class ProductDataStore{  public static ProductDataStore Current { get; } = new ProductDataStore();  public List<ProductDto> Products { get; set; }  public ProductDataStore()  {    Products = new List<ProductDto>()    {      new ProductDto { Id = 1, Name = "Laptop" },      new ProductDto { Id = 2, Name = "Phone" },      new ProductDto { Id = 3, Name = "Desktop" }    };  }}public interface ...

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.