ServiceStack Service Design
I am creating a new Service Stack application and i want to know if this is possible for Service Stack; I used the message Design Pattern and i have a lot of Requests Dtos (about 100 Request Dtos); all of my Requests inherit from Base Request and each Request Dto has a corresponding Response Dto; I want to generate a generic Service that contains four methods Get, Post, Put and Delete; each one of these methods take BaseRequest as a Parameter and return BaseResponse as a return value and every concrete DtoRequest determine its rout; Is this applicable in Service Stack; if not Is there any alternative?
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; }
}
You should not try to create a base service that looks for inherited base objects. ServiceStack was not designed to look for inheritance in the REST method signatures. You should stick to specific DTOs for specific requests.
It is fine to have base request/response objects and there are a couple different ways to work with them. Look into these hooks into the services. You can use Request/Response filters or a Service runner. Basically in those methods you can cast the object to your BaseRequest and do any necessary work.
链接地址: http://www.djcxy.com/p/65516.html上一篇: 不执行服务返回视图
下一篇: ServiceStack服务设计