One of the common challenges for developers migrating from the Web Forms environment to MVC is learning how to adjust to a different application life-cycle. Web Forms had a very well defined chain of events that would be triggered prior to a page being rendered, however the lines aren’t as clear within MVC.
Earlier this month I stumbled upon the following document from Cephas Lin provided both a high-level overview and a detailed view of the general life-cycle within an MVC application and I thought I would share it :
Basically the life-cycle could be summarized as follows :
- The Application is started through
Application_Startand the appropriate Routes are wired up and configured.
- An HTTP Request comes in and MVC takes over.
- Your Controller that cooresponds to that Route will be created, instantiated and any authorization filtering will be handled (if failed it will send back a failed request).
- Any model binding will occur from the Request to any parameters to populate your values.
- The logic of your Action will be executed as expected and it will find a View that corresponds to the one specified in the Action and pass it the appropriate Model.
- The Model will populate the View and it will be served to the user.
- The Result will be executed and the Controller will be disposed of.
This is a very generalized summary (it doesn’t go into detail about ActionFilters etc.). Hopefully it might help developers that are just migrating to MVC better understand what is going on behind the scenes.
If you wanted a more detailed exploration of it, I would recommend reviewing over the detailed view of the document above and checking out the following other related resources :