In CQRS, how do you build the response when creating an entity?

前端 未结 5 1909
心在旅途
心在旅途 2021-01-12 22:02

If using CQRS and creating an entity, and the values of some of its properties are generated part of the its constructor (e.g. a default active value for the

5条回答
  •  情歌与酒
    2021-01-12 22:16

    You would need to create guid before creating an entity, then use this guid to query it. This way your command 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();
        }
    

提交回复
热议问题