我正在创建一个新的Service应用程序,我想知道这对Service是否可行;我使用了message模式,并且我有很多请求Dto (大约100个请求Dto);我的所有请求都是从BaseRequest继承而来的,并且每个请求Dto都有一个相应的响应Dto;我想生成一个通用服务,它包含四个方法Get、Post、Put和Delete;这些方法中的每一种方法都以BaseRequest作为参数并返回BaseResponse作为返回值,并且每个具体的DtoRequest都确定它的rout;这是否适用于Service;如果没有选择的话?
public class OrganizationService : ServiceStack.Service
{
public BaseResponse Post(BaseRequest request)
{
throw new NotImplementedException();
}
public BaseResponse Update(BaseRequest updateRequest)
{
throw new NotImplementedException();
}
public BaseResponse Delete(BaseRequest deleteRequest)
{
throw new NotImplementedException();
}
public BaseResponse Get(BaseRequest deleteRequest)
{
throw new NotImplementedException();
}
public BaseResponse Any(BaseRequest retrieveRequest)
{
throw new NotImplementedException();
}
}
[Route("/entities")]
public class RetrieveEntityRequest : BaseRequest, IReturn<RetrieveEntityResponse>
{
/// <summary>
/// A unique identifier for the entity.
/// </summary>
public Guid MetadataId { get; set; }
/// <summary>
/// Gets or sets the name of the entity to be retrieved.
/// </summary>
public String Name { get; set; }
/// <summary>
/// Gets or sets a filter to control how much data for the entity is retrieved.
/// </summary>
public EntityFilters EntityFilters { get; set; }
/// <summary>
/// Gets or sets whether to retrieve the metadata that has not been published yet.
/// </summary>
public Boolean RetrieveNotPublishedData { get; set; }
}发布于 2014-03-11 19:43:20
不应尝试创建查找继承的基本对象的基本服务。ServiceStack不是为在REST方法签名中查找继承而设计的。对于特定的请求,您应该坚持特定的DTO。
有基本的请求/响应对象是可以的,并且有几种不同的方法来处理它们。看看这些钩入服务部门。您可以使用请求/响应筛选器或服务运行程序。基本上,在这些方法中,您可以将对象转换为您的BaseRequest并执行任何必要的工作。
https://stackoverflow.com/questions/22295313
复制相似问题