1 min read

Create an Asp.Net Core MVC app with the repository pattern Part 4 – Create a Controller that implements the order interface.

First in the constructor of the OrderController inject the IOrder repository.

        private readonly IOrderRepository orderRepository;
        public OrderController(IOrderRepository orderRepository)
        {
            this.orderRepository = orderRepository;
        }

Next in the controller return all orders and pass to the view.

        public IActionResult Index()
        {
            var orders = orderRepository.GetAllOrders();
            return View(orders);
        }

Next it’s time to configure the configureservices of the mvc app to use the mockdatarepository.

Leave a Reply