Building a Web API 2 project from scratch using OWIN/Katana .NET Part 5: adding an IoC
July 16, 2015 4 Comments
Introduction
In the previous post we transformed the CustomersApi application a little bit. We added a customer repository and a customer service. We also transformed the Get action method of CustomersController into an asynchronous one.
We ended up having to construct the dependencies of CustomersController in the constructor like this:
public CustomersController() { _customerService = new CustomerService(new CustomerRepository()); }
In this post we’ll get rid of this direct control over the controller dependencies. Instead, we’ll let an ICustomerService object be injected into the controller through its constructor.