HttpControllerDescriptor封装了某个HttpController类型的元数据,我们可以将它视为某个HttpController类型的描述对象。HttpActionDescriptor也类似。上一篇中说到AbpApiControlerAction信息分别封装于DynamicApiControllerInfoDynamicApiActionInfoAbpHttpControllerDescriptorHttpActionDescriptor有新的实现DynamicHttpControllerDescriptorDyanamicHttpActionDescriptor

 

Action的执行

Action方法的执行最终实现在HttpActionDescriptorExecuteAsync方法中。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
                    }
                });
        }
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
  • 2022-12-23
  • 2022-02-21
  • 2022-12-23
  • 2021-10-15
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案