Configuring the Customer Repository and Web API Controller
Learn about configuring a Web API customer controller with CRUD operations.
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:
Get hands-on with 1400+ tech skills courses.