我在服务端分开我的查询和命令如下:如何返回结果,而将命令查询分离(CQS)
public class ProductCommandService{
void AddProduct(Product product);
}
public interface ProductQueryService{
Product GetProduct(Guid id);
Product[] GetAllProducts();
}
Command Query Separation接受的方法应该改变状态或返回结果。没有问题。
public class ProductController: ApiController{
private interface ProductCommandService commandService;
private interface ProductQueryService queryService;
[HttpPost]
public ActionResult Create(Product product){
commandService.AddProduct(product);
return ???
}
[HttpGet]
public Product GetProduct(Guid id){
return commandService.GetProduct(id);
}
[HttpGet]
public Product[] GetAllProducts(){
return queryService.GetAllProducts();
}
}
我申请上的服务侧命令查询分离,但在控制器类不应用。因为用户可能想要查看创建的产品结果。但commandService在中创建控制器操作metod并不返回创建的产品。
我们将返回给用户什么?所有产品? CQS是否适用于应用程序生命周期?
小心你的术语QCS不是CQRS。无论如何,看到这篇博客文章:http://blog.ploeh.dk/2014/08/11/cqs-versus-server-generated-ids/ –