In this chapter, we will discuss the overall MVC pipeline and the life of an HTTP application via the ASP.NET MVC framework. A life cycle at a high level is simply a series of steps or events used to handle a request type or to change the application status. You may already be aware of different life cycles in the framework, the concept is not unique to MVC.
The ASP.NET webform platform, for instance, has a complex page life cycle. Other. NET platforms, such as Windows phone applications, have their own life cycles for application. One thing that applies to all these platforms regardless of technology is that understanding the processing pipeline can help you make better use of the available functions and MVC is no different.
MVC two life cycles −
- The application life cycle
- The request life cycle
Application Life Cycle
The life cycle of the application refers to the time when the application process actually starts to run IIS until it stops. This is marked by the application start and end events in your application’s startup file.
Request Life Cycle
It is the sequence of events that occur when our application processes a HTTP request. The point of entry for each MVC application starts with routing.
After receiving a request, the ASP.NET platform finds out how it should be handled through the URL routing module. The modules are. NET components that can be connected to the life cycle of the application and add functionality.
The routing module matches the incoming URL with the routes we define in our application. All routes have a related route handler and this is the point of entry to the MVC framework.
The MVC framework transforms the route data into a concrete controller capable of handling demands. After the controller is created, action execution is the next major step.
A component called the action invoker finds and chooses a suitable action method for invoking the controller. After our results have been prepared, the next stage triggers the execution of the result.
MVC separates the result declaration from the result execution. If the result is a view type, the view engine is called and it finds and returns our view. If the result is not a view, the result of the action will be executed separately. This execution results in a real answer to the original HTTP request.