开发者

ASP.NET MVC Controller Factory life cycle

开发者 https://www.devze.com 2023-01-16 08:40 出处:网络
The DefaultControllerFactory contains three different methods: GetControllerInstance CreateController GetControllerType

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

精彩评论

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

关注公众号