Understanding MVC Core startup class
First the request will come to Main method, Main method will create a HOST [It can be IIS for .NET framework]. This host can be thought of your servant that will do exactly what you say. Here what we say is put inside startup class with two method
- ConfigureServices ----->Here you need to add types of services that your servant will provide
- Configure-------------->Here what are the steps or stages that servant has to follow for each request raised by the client.
ConfigureServices
Example : If, I need servant to provide controller and view services[This service is nothing but set of rules that servant has to follow like "where is the controller folder located", "controller name should end with "Controller", "How the controller should map to the action method and so on ] then I need to add "services.AddControllersWithViews()" in ConfigureServices method.
Configure
Here I need to put the different and required stages that request has pass through. It is our wish to give only stages that are required for our project, there is no force to put all stages.
Example :
I am using app.UseRouting() stage or event that is needed for my project.
app.UseAuthentication() stage or event that I need for all users to give their username and password before accessing my application.
Here in this method ordering of event are much important
Need of CreateBuilder
------------------------------
Since all ASP.NET Core applications are built for running under any operating system so to support for running our applications under any OS we need to create HOST which will allow us to run our applications under any OS. Hence we need below part of the code.
Comments
Post a Comment