ServiceStack - 属性知道它从哪个类调用?

时间:2014-04-07 06:05:58

标签: c# asp.net-mvc servicestack

说,我有一个像这样的LogAttribute类:

  public class LogAttribute : RequestFilterAttribute {
    public override void Execute(IHttpRequest req, 
                                 IHttpResponse res, 
                                 object dto) { /*...*/ }
  }    
  [Log]
  public class TransportService : Service { /*...*/ }
  [Log]
  public class HealthService : Service { /*...*/ }

LogAttribute类如何知道它从哪个类调用?即TransportService还是HealthService?

1 个答案:

答案 0 :(得分:1)

您可以使用传入的Request DTO以及ServiceStack维护的有关您服务的元数据,例如:

var serviceType = HostContext.Metadata.GetServiceTypeByRequest(dto.GetType());