:::: MENU ::::

Asp.Net Web API with MVC 6

The latest version of Microsoft web technologies Asp.Net 5 and Mvc 6 have very big differences.

You can find some of  this new features below

  • ASP.NET vNext includes new cloud-optimized versions of MVC 6, Web API 3, Web Pages 4, SignalR 3, and Entity Framework 7.
  • Now Mvc has no dependency to System.Web dll.
  • There is a project.json instead of classic global.asax file.
  • There is Ioc container to manage all dependencies
  • Project structure is more modern and have some javascript tools like gulp.
  • Finally all these Microsoft technologies are open source and cross platform, so we are able to develop apps on Linux or Mac.

Now we will build and Web API on MVC 6 structure.

As a first step we will create a project with below settings.


Solution Explorer will shown like this


I’ve added Model Folder to Project and TodoItem.cs class with below code

ITodoRepository.cs Interface with below code, I’ve added an interface to add as a dependency Injection instead of TodoRepository directly.

and Implementation of interface TodoRepository.cs under the Model Folder with following code

Now we will register repository into the the DI container in Startup.cs file with below code.

As a last step we will create a Todo Controller with below code and we are ready to test

Now API is ready, your solution explorer should be like below image.


You can use Fiddler or Postman to test.I hope tutorial help you. If you have any question about tutorial you can leave a comment.

You can find source code here :https://github.com/hamdiceylan/WebApiWithMvc6

So, what do you think ?