Table of Content
AddMVCCore method registers only a bare minimum services that we need to start an MVC Application. It Registers the lower level services like Controller Factory, which creates the controllers, services that selects the Action method & services that invoke the Action method. It also includes model binding services etc.
We can create three different types of web applications (or any combination of them) using the MVC Services. They are
- MVC (Controller with View)
- Web API
- Razor Pages
The above application types require additional services to work. This is where the methods like
AddRazorPages comes into picture.
AddMvc Vs AddController Vs AddControllersWithViews Vs AddRazorPages
The above methods first invoke the
AddMvcCore method and then go onto registers the additional services. The following table shows list of services, that each of the above methods registers
|MVC Core Services|
Controller Creation & Activation, Model Binding
|Support for Views|
(View Engine and related infrastructure, HTMLHelper, View Components, Tempdata, AntiForgery, Component rendering, etc )
|Razor View Engine|
|Support for Razor Pages||No||No||Yes||Yes|
The AddController method Registers everything that is needed for Web API Development. The services include Support for Controllers, Model Binding, API Explorer, Authorization, CORS, Validations, Formatter Mapping, etc.
The AddControllersWithViews method registers everything that is needed for Web App Development using Controllers and Views. It registers everything that
AddController installs plus the support for Views. These include View Engine and related infrastructure, HTMLHelper, View Components, Tempdata, AntiForgery, Component rendering, etc
The AddRazorPages method registers everything everything needed for Web app development using the Razor Pages. It installs all the services except API Explorer, CORS & Formatter Mapping. It also installs the support for the support for Views, which includes View Engine and related infrastructure, HTMLHelper, View Components, Tempdata, AntiForgery, Component rendering, etc
The AddMvc method installs all the services.