The Circle of Life…cycle of MVC Applications

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 :

  1. The Application is started through Application_Start and the appropriate Routes are wired up and configured.
  2. An HTTP Request comes in and MVC takes over.
  3. 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).
  4. Any model binding will occur from the Request to any parameters to populate your values.
  5. 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.
  6. The Model will populate the View and it will be served to the user.
  7. 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 :