Revisiting repositories and the controller

We are now ready to facilitate interaction between our model and database via our newly created repositories. After making the appropriate changes to ProductRepository, it will look like this:

    using System.Collections.Generic;    using System.Linq;    using FlixOne.BookStore.ProductService.Contexts;    using FlixOne.BookStore.ProductService.Models;    namespace FlixOne.BookStore.ProductService.Persistence    {        public class ProductRepository : IProductRepository        {            private readonly ProductContext _context;            public ProductRepository(ProductContext context)            {                _context = context;            }            public void Add(Product Product)            {                _context.Add(Product);                _context.SaveChanges();            }            public IEnumerable<Product> GetAll()            { return _context.Products.ToList(); ...

Get Building Microservices with .NET Core 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.