ServiceStack ResponseFilterAttribute 未被调用 [英] ServiceStack ResponseFilterAttribute not being called
问题描述
//---------------------------------------------------------------------
//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> { ...
我正在使用上面的代码测试 ToDo 列表示例项目上的 Req/Res 过滤器属性.因此,除了两个额外的属性外,示例项目没有其他任何更改(我认为).
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.
他们不应该在 & 之前成对开火吗?在这种情况下,在 Rest 调用之后?是我的理解不正确还是我做错了什么?在此先感谢您的帮助.
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.
推荐答案
将您的请求和响应过滤器与相应的请求和响应 DTO 一起使用
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
};
}
}
这篇关于ServiceStack ResponseFilterAttribute 未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!