HttpControllerDescriptor封装了某个HttpController类型的元数据,我们可以将它视为某个HttpController类型的描述对象。HttpActionDescriptor也类似。上一篇中说到Abp将ApiControler与Action信息分别封装于DynamicApiControllerInfo,DynamicApiActionInfo。Abp种HttpControllerDescriptor与HttpActionDescriptor有新的实现DynamicHttpControllerDescriptor,DyanamicHttpActionDescriptor。

 

Action的执行

Action方法的执行最终实现在HttpActionDescriptor的ExecuteAsync方法中。DyanamicHttpActionDescriptor也重写了ExecuteAsync,并且将Action的返回值类型定义为AjaxResponse。

 

 

ABP之动态WebAPI
        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
                    }
                });
        }
ABP之动态WebAPI
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-20
  • 2021-07-13
  • 2022-02-02
  • 2022-02-17
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-10
  • 2022-02-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-15
相关资源
相似解决方案