Example Analysis of .NET MyMVC Framework implementing Action
This article mainly introduces. NET MyMVC framework implementation of Action example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
In the GetHandler method of AjaxHandlerFactory, you will finally create an ActionHandler, which is a HttpHandler, which will be called in step 15 of the pipeline.
Note: AjaxHandlerFactory's GetHandler method is called in step 10, and step 12 is preparing Session (non-in-process mode), so you must decide how to use Session before step 12.
All Action code is executed in ActionHandler:
Internal class ActionHandler: IHttpHandler {internal InvokeInfo InvokeInfo; public void ProcessRequest (HttpContext context) {/ / invoke the core utility class and execute Action ActionExecutor.ExecuteAction (context, this.InvokeInfo);}
The implementation process of ExecuteAction is as follows:
Internal static void ExecuteAction (HttpContext context, InvokeInfo vkInfo) {if (context = = null) throw new ArgumentNullException ("context"); if (vkInfo = = null) throw new ArgumentNullException ("vkInfo"); / / call method object result = ExecuteActionInternal (context, vkInfo); / / set OutputCache OutputCacheAttribute outputCache = vkInfo.GetOutputCacheSetting (); if (outputCache! = null) outputCache.SetResponseCache (context) / / the result returned by the processing method IActionResult executeResult = result as IActionResult; if (executeResult! = null) {executeResult.Ouput (context);} else {if (result! = null) {/ / normal type result context.Response.ContentType = "text/plain"; context.Response.Write (result.ToString ()) } internal static object ExecuteActionInternal (HttpContext context, InvokeInfo info) {/ / prepare the parameters to be passed to the calling method object [] parameters = GetActionCallParameters (context, info.Action); / / call method if (info.Action.HasReturn) return info.Action.MethodInfo.Invoke (info.Instance, parameters); else {info.Action.MethodInfo.Invoke (info.Instance, parameters); return null;}}
I didn't mention the timing of calling SetResponseCache () earlier, but it's right here: after the Action is executed.
Once the OutputCache is set, the return value is processed.
In the previous code, there is another important call:
/ prepare the parameter object [] parameters = GetActionCallParameters (context, info.Action) to be passed to the calling method; thank you for reading this article carefully. I hope the article "sample Analysis of the implementation of Action in the .NET MyMVC Framework" shared by the editor will be helpful to you. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!