我有服务:
[SomeResponse]
public class SomeService : ServiceBase {
public string[] CacheMemory{ get; set; }
//....
}
public class SomeResposeAttribute : ResponseFilterAttribute {
public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto) {
//I want to access SomeService->CacheMemory here?? How?
}
}
现在,如果我需要在响应属性中对CacheMemory
执行某些操作,然后再将其发回。我如何获得它?谢谢。
答案 0 :(得分:2)
过滤器属性无法访问Service实例,您可以使用IRequest.Items
字典将对象传递给ServiceStack's Request Pipeline中的不同处理程序,例如:
[MyResponseFilter]
public class SomeService : Service
{
public string[] CacheMemory { get; set; }
public object Any(Request request)
{
base.Request.Items["CacheMemory"] = CacheMemory;
//...
return response;
}
}
public class MyResponseFilterAttribute : ResponseFilterAttribute
{
public override void Execute(IRequest req, IResponse res, object dto)
{
var cacheMemory = (string[])req.Items["CacheMemory"];
}
}