【问题标题】:Do I have access to the request dto when I'm handling exceptions occuring outside of services?当我处理服务之外发生的异常时,我是否可以访问请求 dto?
【发布时间】:2015-12-07 21:14:27
【问题描述】:

使用 ServiceStack,在两个地方实现异常处理/日志记录很重要:

  1. Inside of eachServiceRunner<T>.

       public class MyServiceRunner<T> : ServiceRunner<T>
       {    
            public override object HandleException(IRequestContext requestContext, T request, Exception ex)
              {
                    // Implement your exception handling/logging here.
                    // T request is your request DTO.
              }
        }
    
  2. Inside of AppHost,以便您可以处理服务之外发生的未处理异常。

    public override void Configure(Container container)
    {
        ExceptionHandler = (req, res, operationName, ex) =>
        {
            //Handle Unhandled Exceptions occurring outside of Services
            //E.g. Exceptions during Request binding or in filters:
        }
     }
    

我的问题:

  • 在 #1 中,您可以轻松访问请求 DTO(即用于记录目的)。
  • 在处理服务之外发生的异常时,我是否有权访问请求 DTO(或等效的请求负载)?

【问题讨论】:

    标签: c# servicestack servicestack-bsd


    【解决方案1】:

    在 ServiceStack v4 中,请求 DTO 可从 IRequest.Dto 获得,但您可以使用 IAppHost.ServiceExceptionHandlersIAppHost.UncaughtExceptionHandlers 注册您的服务和未知异常处理程序

    在 ServiceStack V3 中,您可以注册一个 GlobalRequestFilter,它将请求 DTO 存储在 IRequestContext.Items 字典中,稍后您可以从请求上下文中获取该字典。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-26
      • 2020-06-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多