1

私はサービスを持っています:

[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ここで、返信する前に応答属性で何かをする必要がある場合。どうすればアクセスできますか? ありがとうございました。

4

1 に答える 1

2

Filter Attributes は Service インスタンスにアクセスできません。ディクショナリを使用して、ServiceStack の Request PipelineIRequest.Items全体でさまざまなハンドラにオブジェクトを渡します。たとえば、次のようになります。

[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"];
    }
}
于 2015-06-27T12:58:53.130 に答える