In CQRS, how do you create an answer when creating an object?

When using CQRS and creating an object, and the values ​​of some of its properties are generated by part of its constructor (for example, the default value activefor a property statusor the current datetime for createdAt), how do you include this as part of your answer if your command handlers cannot return values?

+4
source share
4 answers

You will need to create a guid before creating the entity, and then use this guid for the request. That way your handlers always return void.

    [HttpPost]
    public ActionResult Add(string name)
    {
        Guid guid = Guid.NewGuid();
        _bus.Send(new CreateInventoryItem(guid, name));
        return RedirectToAction("Item", new { id = guid});
    }


    public ActionResult Item(Guid id)
    {
        ViewData.Model = _readmodel.GetInventoryItemDetailsByGuid(id);
        return View();
    }
+5
source

, , CQRS , . stack.pop() .

CQS - , CQRS, - , , , .

CQS ​​ , ( ). , , , .

, , Meyer CQS, , , , , .

,

, : ?

: , , a: , !! a . - , . , !! ! Result.make(...)?

. ( , , ). , , , , , ; - . , initialize .

( - , .754)

-.

CQRS CQS , [ ] , , , CQS, CQRS.

, CQS CQRS . CQRS , "" . . , , , - " ", , - , - .

+5

:

+4

According to my understanding of CQRS, you cannot request an aggregate, and the command handler could not return any value. The only acceptable way to interact with the aggregate is by listening to raised events. This can be done simply by requesting a read model if changes are reflected synchronously from events to the read model.

In case changes in the reading model are asynchronous, everything is more complicated, but there are solutions.

0
source

Source: https://habr.com/ru/post/1667842/


All Articles