Understanding ASP.NET MVC 5 Application Lifecycle

This post shows the lifecycle of every ASP.NET MVC 5 application, beginning from receiving the HTTP request from the client to sending the HTTP response back to the client. It is designed both as an education tool for those who are new to ASP.NET MVC 5 and also as a reference for those who need to drill into specific aspects of the application.

ASP.NET MVC 5 Application Lifecycle – High-Level View, mvc lifecycle, mvc request, mvc, request, lifecycle

The entry point of MVC Request life cycle is URL Routing module, the incoming request from IIS pipeline is handed over to URL Routing module which analyses the request and looks up Routing table to figure out which controller the incoming request maps to. Routing Table is a static container of routes defined in MVC application with corresponding controller action mapping. If the route is found in the routing table MVCRoute- MVCRouteHandler Handler executes and brings the instance of MVCHttpHandler MVCHttpHandler. Together they act as a gateway into the MVC Framework. 

MVC handler begins initializing and executing controller. The MVCHttpHandler also takes of converting route data into concrete controller that is capable of serving the request. MVC handler does all this with the help of MVC Controller factory and activator which are responsible for creating an instance of the controller. This is also the place where the Dependency Injection is performed if the application has been designed to invoke parameterized controller constructor and satisfy its dependencies. 

After the controller instance is created the next major step is to find and execute the corresponding action. A component called ActionInvoker ActionInvoker finds and executes the action defined in routing table. Before the action method is called model bindings takes place which maps data from http request to action method parameters. After the model binding, action filters are invoked which includes OnActionExecuting filter. This is followed by action execution and Action Executed filter execution and finally preparing Action Result.

Post a Comment

Previous Post Next Post