ServiceStack ResponseFilterAttribute Error

//--------------------------------------------------------------------- //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 the Req / Res filter attributes in a ToDo List example project using the code above. Thus, nothing else was changed to a sample project (I think), with the exception of two additional attributes.

When I add a todo element, only the request attribute is called. The response attribute was not activated.

Shouldn't they be paired before and after calling Rest in this case? Is my understanding wrong or am I doing something wrong? Thank you for your help.

+4
source share
1 answer

Use request and response filters with corresponding DTO requests and responses

  [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 }; } } 
0
source

Source: https://habr.com/ru/post/1433219/


All Articles