来自嵌套服务的访问请求

时间:2014-06-03 14:48:19

标签: c# servicestack

是否有一种从嵌套服务调用访问Request对象的简单方法?

例如:

// Entry Point
public class ServiceA : Service
{
    public AResponse Get(ARequest request)
    {
        // Request is ok in entry point.

        // Now call another service
        var srvResp = TryResolve<ServiceB>().Get(new BRequest{ ... });
    }
}

// Called through Service A
ServiceB : Service
{   
    public BResponse Get(BRequest request)
    {
        // Request is not set here (null).
    }
}

1 个答案:

答案 0 :(得分:3)

您应该使用ResolveService<T>类提供的Service方法来解析该服务。这将使Request对象可用于您正在解析的服务。

public class ServiceA : Service
{
    public AResponse Get(ARequest request)
    {
        // Request is ok in entry point.

        // Use ResolveService<T> here not TryResolve<T>
        var srvResp = ResolveService<ServiceB>().Get(new BRequest{ ... });
    }
}

希望有所帮助