//---------------------------------------------------------------------
//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 List示例项目中的Req / Res Filter属性。所以除了两个额外的属性之外,没有其他任何内容被更改为示例项目(我认为)。
当我添加待办事项时,只调用了请求属性。响应属性未被触发。
他们不应该在一对之前开火。在这种情况下休息之后?我的理解不正确还是我做错了什么?谢谢你的帮助。
答案 0 :(得分:0)
将您的请求和响应过滤器与相应的请求和响应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
};
}
}