[Dot Net Core](Graphic series )8. Resolve Controller class process
The previous section summarized the process from Http Request to Dot Net Core MVC. This section will discuss the general process of Controller in Dot Net Core being resolved.
First, continuing the previous article, ControllerActionInvoker.InvokeAsync will execute the generation of the controller instance:
The above figure shows that ControllerActionInvoker collects ControllerContext and ControllerActionInvokerCacheEntry information into its own properties. Once ControllerActionInvoker.InvokeAsync is executed, it will start from step S1, call ControllerActionInvoker.InvokeFilterPipelineAsync, call Next after S2, and call ControllerActionInvoker.InvokeInnerFilterAsync at step S3. It will come to a very important stage, which is to continue to generate Controller instance through ControllerFactory.
Code:
var controller = controllerActivator(controllerContext);
First, ActivatorUtilities will be executed to execute the GetService function. In step S1, the ControllerContext.HttpContext.RequestServices will first obtain ServiceProviderEngine.CreateScope, and the ServiceProviderScope can be obtained by executing this function.
Then in step S2, by obtaining the Controller Type from the ControllerContext, execute ServiceProviderScope.GetService as a parameter, and in step S3 to ServiceProviderEngine.GetService, it will call the IServiceProviderEngineCallbackOnResolve of the ServiceProvider.
The following figure is to log the entire call process as a track:
Executing ControllerActionInvoker.InvokeAsync from the above figure will start from Authorization Filter Case, then Resource Filter Case、 Exception Filter Case、 Action Case, to ActionBegin to find ControllerFactory to generate controller instance, then to ActionFilter Case to execute Action Method, and finally return ActionResult.
The above is a general overview of the process for reference.