【发布时间】:2016-09-16 16:18:36
【问题描述】:
我目前有一个 ServiceStack 服务,它只是将请求中继到内部 ServiceStack 服务。
中继服务是这样设置的(代码以简短为例):
public class RelayService : Service
{
public SomeDTO Get(FetchSomething request)
{
try
{
return new JsonServiceClient(settings.OtherServiceURL).Get(request);
}
catch (Exception)
{
throw;
}
}
public void Put(PersistSomething request)
{
try
{
new JsonServiceClient(settings.OtherServiceURL).Put(request);
}
catch (Exception)
{
throw;
}
}
}
我的问题是:
最佳实践是为每个请求新建一个 JsonServiceClient 吗?还是应该注入一个实例?
由于中继服务可以包含返回 DTO 或 void 的 Put/Get 变体,是否有更简洁的方法将所有调用中继到后备 ServiceStack 服务,而不必复制中继服务中的每个方法?是否可以使用 Any() 以一种或几种方法完成所有这些操作?
感谢您的任何意见。
【问题讨论】:
标签: c# servicestack