Back to Mvchandler's ProcessRequest, Defaultcontrollerfactory.createcontroller (RequestContext, requiredString) to return IController instance. Here's a look at Defaultcontrollerfactory's code:
By reflecting to create a Controller instance, the Getcontrollertype has some cache processing to avoid the performance problems caused by frequent use of reflection. Go on
Mvchandler.processrequest (), after getting the controller instance, Mvchandler starts calling Controller.execute () for further action, while further encapsulating its context, in addition to the previous RequestContext, plus the current reference to this Controller object, class name ControllerContext.
namespace SYSTEM.WEB.MVC {
using System.Web.Routing;
[AspNetHostingPermission (System.Security.Permissions.SecurityAction.LinkDemand, level = Aspnethostingpermissionlevel.minimal)]
[AspNetHostingPermission ( System.Security.Permissions.SecurityAction.InheritanceDemand, level = Aspnethostingpermissionlevel.minimal)]
public class Controllercontext:requestcontext {
Public controllercontext (HttpContextBase HttpContext, RouteData Routedata, IController Controller)
: Base (HttpContext, Routedata) {
if (Controller = null) {
throw new ArgumentNullException ("Controller");
}
Controller = Controller;
Public ControllerContext (RequestContext RequestContext, IController Controller)
: this (getrequestcont Ext (requestcontext). HttpContext, Getrequestcontext (RequestContext). Routedata, controller) {
}
Public IController controller {
get;
PrivaTe set;
}
Internal static RequestContext Getrequestcontext (RequestContext requestcontext) {
if (request context = = null) {
throw new ArgumentNullException ("RequestContext");
return requestcontext;
}
}
}