Bootstrapping & Request-Response Process in MVC.
Bootstrapping Process in MVC :
Let’s create one ASP.NET Core application and we will try to understand the flow of bootstrap process. Bootstrapping process starts with program.cs. Program.cs is responsible for starting web server where it invokes kestrel web server and makes IIS as a front end proxy.
1.Program.CS :
- program.cs is the entry point of our app, where we configure the Web host. The main purpose of the Program class is to configure the applications infrastructure.
- The Program class contains the method Main, which is the entry point of the ASP.NET Core applications.
- The program class creates the Web Host at the startup. It configures Kestrel(Web-Server), IISIntegration and other Configurations.
- The Web host is responsible for starting the app and running it & it is created when the application is start.
2. Startup.CS :
- Now question is startup.cs file is mandatory or not? Yes, startup.cs is mandatory, Startup.CS has an access modifier like public, private.startup class has an important methods like Constuctor , ConfigureServices & configure with HTTP request pipelines
Constructor for Startup Class :
The startup class has constructor with one or three parameters.
- IApplicationBuilder : this interface contain properties and method related to current Enviroment.
- IHostingEnvironmen : this interface contain properties and method related to web hosting environment on which application is running.
- IloggerFactory :this interface provides configuration for the logging system.
The startup class contains two methods: ConfigureServices and Configure.
ConfigureServices :
- Startup class which is used to configure services for application. when any request come to application ConfigureService method will be called first.
- In ConfigureServices method you can register dependent classes, after registering dependent class, it can be used anywhere in the web application. In ConfigureServices method, the services which we want to use in application are added here.
- ConfigureServices method includes IServiceCollection parameter to register the services. This method must be declared with a public access modifier.
Configure method :
- The Configure method is used to specify how the application will respond in each HTTP request.
for example; When the end-user sends the request it will go to the controller and get the response. When the application runs the program.cs and startup.cs runs only one time.
Summary :
The Main method of the program.CS class is the entry point of our application. It configures & builds the Web host. The web host is responsible for running our app. Most of the plumbing required to configure host is already done for us in the createdefaultbuilder method, which is invoked in the Main method.
Request-Response Process 🔁 :
- When the application is running in the web browser it show the index view because in configure method default route is set to the Controller that is HomeController and action is loaded in Browser. When web application is running, it get ready to accept the user request. When end user send request to browser it go to controller then Controller send request to model and Model access the data from sql server and that data loads on view and give response to end user. This process is called request -response process.
- When we sends the request it first goes to the controller and loads it.
- In above figure HomeController first loaded and fire the index which returns View().
- After that view is render on to the browser the Home page shows the below👇
I hope this guide has been helpful for you 😃!!!