HttpControllerDescriptor封装了某个HttpController类型的元数据,我们可以将它视为某个HttpController类型的描述对象。HttpActionDescriptor也类似。上一篇中说到Abp将ApiControler与Action信息分别封装于DynamicApiControllerInfo,DynamicApiActionInfo。Abp种HttpControllerDescriptor与HttpActionDescriptor有新的实现DynamicHttpControllerDescriptor,DyanamicHttpActionDescriptor。
Action的执行
Action方法的执行最终实现在HttpActionDescriptor的ExecuteAsync方法中。DyanamicHttpActionDescriptor也重写了ExecuteAsync,并且将Action的返回值类型定义为AjaxResponse。
public override Type ReturnType { get { return typeof(AjaxResponse); } } public override System.Threading.Tasks.Task<object> ExecuteAsync(HttpControllerContext controllerContext, System.Collections.Generic.IDictionary<string, object> arguments, System.Threading.CancellationToken cancellationToken) { return base .ExecuteAsync(controllerContext, arguments, cancellationToken) .ContinueWith(task => { try { if (task.Result == null) { return new AjaxResponse(); } if (task.Result is AjaxResponse) { return task.Result; } return new AjaxResponse(task.Result); } catch (AggregateException ex) { ex.InnerException.ReThrow(); throw; // The previous line will throw, but we need this to makes compiler happy } }); }