...
/Configuring the Customer Repository and Web API Controller
Configuring the Customer Repository and Web API Controller
Learn about configuring a Web API customer controller with CRUD operations.
We'll cover the following...
Now we will configure the repository to be called from within a Web API controller.
Defining a Web API controller for working with customer
We will register a scoped dependency service implementation for the repository when the web service starts up and then use constructor parameter injection to get it in a new Web API controller for working with customers. To show an example of differentiating between MVC and Web API controllers using routes, we will use the common /api
URL prefix convention for the customer’s controller:
Step 1: In Program.cs
, import the namespace for working with our customer’s repository, as shown in the following code:
using Northwind.WebApi.Repositories; // ICustomerRepository, CustomerRepository
Step 2: In Program.cs
, add a statement before the call ...