IController vs ControllerBase vs Controller vs MyController?

I have an ASP.NET MVC project that I created and was looking at some documentation when I came across how the controller class is implemented. I am very familiar with OOP, but I have a few questions about why this is implemented in this way.

I looked at the codeproject and a few stack overflows , but cannโ€™t find the same thing that interests me.

  • in MVC 5 What is the purpose of this chain: IController โ†’ ControllerBase โ†’ Controller โ†’ MyController.
  • If ControllerBase is considered the minimum required to create a controller, then why does it have a Controller class? Or vice versa, if the Controller is a minimal implementation, then ControllerBase is not really a base class?

Thanks in advance!

+4
source share
1 answer

In MVC 5, it ControllerBaseacts only as a simple base class for most of its internal use and internally implements IController.Execute(RequestContext requestContext), and here is a list of the customs that I received from Resharper enter image description here

It then Controllerimplements all the functions for binding filters, models, and views. Therefore, in order to realize yours MyController, you need to get fromController

Your SO link has already explained the purpose of ControllerBaseand Controller.

Thing looks a lot more interesting in MVC 6 (later called ASP.NET MVC Core) when the ASP.NET team converted MVC, WebAPI into one framework

Controller ControllerBase GitHub. <summary> :

Controler.cs

MVC- .

ControllerBase.cs

MVC- .

, ControllerBase. , ASP.NET MVC WebAPI View, MyController ControllerBase. Controller, View JSON WebAPI. Controller.cs View .

+6

Source: https://habr.com/ru/post/1682170/


All Articles