ServiceStack ResponseFilterAttribute not being called

大兔子大兔子 提交于 2019-12-07 08:15:28

问题


//---------------------------------------------------------------------
//Aspect Filters
public class RequestAspectAttribute : RequestFilterAttribute {
  public RequestAspectAttribute() { } //debug point was hit
  public RequestAspectAttribute(ApplyTo applyTo) : base(applyTo) { }
  public override void Execute(IHttpRequest req, IHttpResponse res, object reqDto) {
      //This code is executed before the service 
      //debug point was hit
  }
}
public class ResponseAspectAttribute : ResponseFilterAttribute {
  public ResponseAspectAttribute() { } //debug point was NOT hit
  public ResponseAspectAttribute(ApplyTo applyTo) : base(applyTo) { }
  public override void Execute(IHttpRequest req, IHttpResponse res, object resDto) {
      //This code is executed after the service 
      //debug point was NOT hit
  }
}
//---------------------------------------------------------------------
//REST Service
[RequestAspect]
[ResponseAspect]
public class TodoService : RestServiceBase<Todo> { ...

I am testing out the Req/Res Filter Attributes on the ToDo List sample project with the code above. So nothing else has been changed to the sample project (I think) except for the two additional attributes.

When I add a todo item, only the request attribute was called. The response attribute didn't get triggered.

Shouldn't they fire up in a pair before & after a Rest call in this case? Is my understanding incorrect or am I doing something wrong? Thank you ahead for your help.


回答1:


Use your request and response filters with respective Request and Response DTO

    [Route("/Hello")]
    [RequestAspect]
    public class HelloRequest
    {
        public string hello { get; set; }
    }
    [ResponseAspect]
    public class HelloResponse
    {
        public string hello { get; set; }
    }
    public class HelloService : Service
    {
        public object Any(HelloRequest req)
        {
            return new HelloResponse
            {
                hello = req.hello
            };
        }
    }


来源:https://stackoverflow.com/questions/12338894/servicestack-responsefilterattribute-not-being-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!