In this recipe, you will learn what POCO controllers are, and why we will use them.
POCO controllers are simple classes decorated with two attributes:
- The
[Controller]
attribute, for the class itself, or its base class - A
routing
attribute, defining its route in the application
They don't inherit from the Controller
class, so they will not be able to return any MVC or WebAPI result as a view, an HttpStatus
code, or any type inheriting from IActionResult
.
We can place them anywhere in the application, at the root of the project, or in a folder named POCOController
. In this exercise, we'll create a class and make it a controller by adding the Controller
attribute on top of it, by following the given steps:
- We'll add
Microsoft.AspNetCore.Mvc
Nuget package to project:
"Microsoft.AspNetCore.Mvc": "2.0.0"
- We will add the MVC service, and use it in
Startup.cs
:
public class Startup { public void...