Identifying controllers

Controllers and actions are usually decorated with attributes and filters in a sort of meta-programming style, which allows developers to understand the purpose of the implemented code. ASP.NET Core follows a set of criteria to find the controllers in our project, usually by using a filesystem convention. Controllers are generally stored in the Controllers folder.  

In order to be identified by the routing system, a controller class needs to be compliant with one of the following rules:

  • The class is suffixed with Controller, or it inherits from a class that has the Controller suffix
  • The class is decorated with the [Controller] or the [ApiController] attribute, which identifies it as a controller class
As we mentioned in Chapter 4, Dependency Injection, it is recommended to define controller dependencies using the constructor or action injection explicitly. The dependency injection approach improves the testability and maintainability of the controller.

Now, let's see how a widespread concept like inheritance can be applied to the controllers in order to extend their functionalities, and how ASP.NET Core provides some of the bases attributes to the controller classes using this technique. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.80.122