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

前端 未结 5 1871
心在旅途
心在旅途 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:29

    What I ended up doing is I created a 3rd type: CommandQuery. Everything gets pushed into either a Command or Query whenever possible, but then when you have a scenario where running the command results in data you need above, simply turn to the CommandQuery. That way, you know these are special circumstances, like you need an auto-id from a create or you need something back from a stack pop, and you have a clear/easy way to deal with this with no extra overhead that creating some random dummy guid or relying on events (difficult when you are in a web request context) would cause. In a business setting, you could then discuss as a team if a CommandQuery is really warranted for the situation.

提交回复
热议问题