开发者

ASP.NET MVC Controller Factory life cycle

The DefaultControllerFactory contains three different methods:

  1. GetControllerInstance
  2. CreateController
  3. GetControllerType

When is each method executed in the request lifetime? I've seen custom controller factories where one of these methods is overridden and implemented bu开发者_高级运维t I can't seem to find details on the execution path of each one.


CreateController gets called.
It first calls GetControllerType to figure out type of the controller, then passes this type to GetControllerInstance.

Because it is easier (and often enough) to (only) override GetControllerInstance (so that the logic behind selecting the type remains the same), you'd often see this happening.


Update for MVC3, the methods are called in this order.

GetControllerType gets called first and gets called twice.

  1. GetControllerType
  2. GetControllerSessionBehavior
  3. CreateController
  4. GetControllerType
  5. CreateControllerInstance
  6. ReleaseController
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜