[Dot Net Core](Graphic series ) 14. Simple describe How and when ControllerFactory is formed
The previous section showed how to use delegate functions to save memory content. This section will explain and record when and how Dot Net Core forms ControllerFactory content.
No matter what the architecture is, when a Controller is to be generated, a ControllerFactory is required. In Dot Net Core, when Host executes EndpointMiddleware for the first time, it will generate ControllerFactory. The trick to generating a ControllerFactory is exactly what was provided in the previous section.
Review the diagram in “Http Request to Dot Net Core MVC”:
When the Request is sent to the MVC Controller, step S4 in the above figure is to call and execute the ControllerFactory delegate function through the ControllerFactory of ControllerActionInvokerCacheEntry.
When Host executes StartAsync, the first time EndpointMiddleware is executed, ControllerActionInvokerCache.GetCachedResult will do the action of generating ControllerFactory. Using the ControllerFactoryProvider.CreateControllerFactory function, the ControllerActionDescriptor information is parsed to form the ControllerFactory delegation function.
This delegated function will then be assigned to ControllerActionInvokerCacheEntry.ControllerFactory. ControllerActionInvokerCacheEntry will be assigned to ControllerActionInvoker._cacheEntry. Its relationship diagram is as follows:
The thick red box at the bottom of the above figure indicates that ControllerActionInvokerCacheEntry is generated by the ControllerActionInvokerCache.GetCachedResult function, and the ControllerFactory delegate function is specified to ControllerActionInvokerCache.ControllerFactory, and this delegate function can obtain the information contained in the information generated by ControllerActionDescriptor ‘s memory. For the subsequent actions, please refer to the section of “Http Request to Dot Net Core MVC” to generate Controller. The above is a reference and record of how ControllerFactory is generated.