Points to Remember:
- Support of controller is available for all the methods. So, if you need only a controller then you can use any of the methods.
- The model binding feature is also available for all the methods. Model binding is used to map the incoming data to the controller action methods.
- Except for the AddRazorPages method, all other methods support the API Explorer feature. The API Explorer has used the list of all the available APIs in your application.
- Authorization is available for all four methods. Authorization is basically used to provide the security features,
- Again, except for the AddRazorPages method, all other methods support CORS. CORS is basically a feature that allows CROSS domain call. That means from other domains they can access your method using jQuery AJAX.
- The validation feature is supported by all the methods. Validation is basically used to validate the HTTP Request data. In .NET Core Application, we can implement validation using a concept called Data Annotation.
- Except for the AddRazorPages method, all other methods support the Formatter Mapping feature. The Formatter Mapping feature is basically used to format the output of your action method such as JSON or XML, etc.
- Antiforgery, TempData, and Views features are not available in the AddControllers method.
- The Pages are available only with AddMVC and AddRazorPages method.
- TagHelpers are not available in the AddControllers method and available for rest three methods.
- The memory Cache feature is also not available in the AddControllers method but available with the rest three methods.
Which method to use for our application?
This is depending on which type of application you want to create.
- If you want to create a Web API application where there are no views, then you need to use AddControllers() extension method.
- If you want to work with the Razor Page application, then you need to use the AddRazorPages() extension method into your ConfigureService method of Startup class.
- If you want to develop a Model View Controller i.e. MVC application then you need to use AddControllersWithViews() method. Further, if you want Pages features into your MVC application, then you need to use the AddMVC method.
Nhận xét
Đăng nhận xét