lundi 22 juin 2015

How to return result while applying Command query separation CQRS

I am separating my query and commsnd on service side like this:

public class ProductCommandService{
    void AddProduct(Product product);
}

public interface ProductQueryService{
    Product GetProduct(Guid id);
    Product[] GetAllProducts();
}

Command Query Separation accepts that a method should change state or return a result. There is no problem.

public class ProductController: ApiController{

    private interface ProductCommandService commandService;
    private interface ProductQueryService queryService;

    [HttpPost]
    public ActionResult Create(Product product){
        commandService.AddProduct(product);

        return ???
    }

    [HttpGet]
    public ActionResult GetProduct(Guid id){
        return commandService.GetProduct(id);
    }

    [HttpGet]
    public ActionResult GetAllProducts(){
        return queryService.GetAllProducts();
    }
}

I am applying command query separation on service side but not applying in controller class. Because user may want to see created product result. But commandService works in Create Controller Action metod and does not return created product.

What will we return to user? AllProducts? Will CQRS applly about application lifecycle?

Aucun commentaire:

Enregistrer un commentaire