是否有一种从嵌套服务调用访问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).
}
}
答案 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{ ... });
}
}
希望有所帮助