In this article, I will show you a simple implementation of Dependency Injection in the Web API.
Introduction
In this article, I will show you a simple implementation of Dependency Injection in the Web API. Here we create an application that implements Dependency Injection.
Step 1
Create a Web API application.
Step 2
Create Two Model classes first is "ResponseModel" and another as "ResultModel".
Add the following code in the "ResponseModel.cs".
Add the following code in "ResultModel.cs" class.
Step 3
Add a new Folder to the project.
Add the following code in this interface:
Step 4
Create a Controller "ResponseController".
Add the following code:
Step 5
Now we add a class in the "App_start" folder:
In the "Solution Explorer"
Right-click on the "App_Start" folder.
Select "Add" -> "Class".
In the "WebApi.config" file add the following line of code:
config.DependencyResolver = new SolveController();
Step 6
Execute the application and change the URL to "http://localhost:43200/api/Response".Then the output will be as in the following:
Hands on ASP.NET GridView