我开始使用 ServiceStack 来实现 Web 服务 API。我正在尝试尽可能多地遵循示例和最佳实践,但有时这并不容易(似乎许多示例尚未更新以遵循新的 API 设计)。
我目前拥有的是这样的:
- 一个名为MyApp.ServiceInterface包含服务/方法实现的程序集
- MyApp.ServiceModel包含请求和响应类型以及 DTO的程序集
在MyApp.ServiceModel大会中,我有例如:
namespace MyApp.ServiceModel
{
    public abstract class ResponseBase
    {
        public ResponseStatus ResponseStatus { get; set; } // for error handling
    }
    [Route("/products/{Id}")]   // GET: products/123
    [Route("/products")]        // GET: products?Name=...
    public class ProductRequest : IReturn<ProductResponse>
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
    public class ProductResponse : ResponseBase
    {
        public Types.Product Product { get; set; }
    }
}
namespace MyApp.ServiceModel.Types
{
    public class Product
    {
        public int Id { get; set; }
        public string Name { get; set; }
        // ...
    }
}
问题:
- 我已经看到了如何命名请求类型的不同方法(例如GetProduct,ProductRequest或只是Product)。推荐的方法是什么?
- 命名是否取决于服务是否为 REST 服务?
- 将请求和响应类型放入单独的(子)命名空间(例如MyApp.ServiceModel.Requests和MyApp.ServiceModel.Responses)是否是个好主意?
- 为什么包含命名的实现的程序集ServiceInterface(不ServiceImplementation适合更好)?