事件溯源命令与事件
我理解命令和事件之间的区别,但在很多情况下,您最终会在本质上相同的两个类(ThingNameUpdateCommand、ThingNameUpdatedEvent)之间出现冗余和映射。对于这些简单的情况,您是否也可以使用事件作为命令?人们是否将所有命令和所有事件序列化到存储中?对我来说似乎有点多余。
I understand the difference between commands and events but in a lot of cases you end up with redundancy and mapping between 2 classes that are essentially the same (ThingNameUpdateCommand, ThingNameUpdatedEvent). For these simple cases can you / do you use the event also as a command? Do people serialise to a store all commands as well as all events? Just seems to be a little redundant to me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所有这些冗余通常都是有原因的,并且出于多种原因,您希望避免将相同的消息用于两个不同的目的:
最后,这些只是数据类,这并不是“硬”代码。有一些方法可以实际避免一些简单场景(例如代码生成)的输入。例如,我知道 Greg 过去曾使用 XML 和 XSD 转换来创建给定域所需的所有类。
我想说,对于很多简单的情况,您可能想质疑这是否真的是领域(即建模行为)还是只是数据。如果只是数据,请考虑不要在此处使用事件源。下面是 Udi Dahan 的演讲链接,内容涉及打破域模型,以便并非所有模型都需要事件溯源。我自己现在也有点认同这种想法。
http://skillsmatter.com/podcast/design-architecture/talk-来自-udi-dahan
All lot of this redundancy is for a reason in general and you want to avoid using the same message for two different purposes for a number of reasons:
In the end these are just data classes, it isn't like this is "hard" code. There are ways to actually avoid some of the typing for simple scenarios like code-gen. For example, I know Greg has used XML and XSD transforms to create all the classes needed for a given domain in the past.
I'd say for a lot of simple cases you may want to question if this is really domain (i.e. modeling behavior) or just data. If it is just data consider not using event sourcing here. Below is a link to a talk by Udi Dahan about breaking up your domain model so that not all of it requires event-sourcing. I'm kind of in line with this way of thinking now myself.
http://skillsmatter.com/podcast/design-architecture/talk-from-udi-dahan
在完成一些示例,特别是 Greg Young 演示文稿 (http://www.youtube.com/watch ?v=JHGkaShoyNs) 我得出的结论是命令是多余的。它们只是来自您的用户的事件,他们确实按下了该按钮。您应该以与其他事件完全相同的方式存储这些数据,因为您不知道这些数据是否要在将来的视图中使用。您的用户确实添加了该商品,然后又从购物篮中删除了该商品,或者至少尝试这样做。您稍后可能希望使用此信息来提醒用户这一点。
After working through some examples and especially the Greg Young presentation (http://www.youtube.com/watch?v=JHGkaShoyNs) I've come to the conclusion that commands are redundant. They are simply events from your user, they did press that button. You should store these in exactly the same way as other events because it is data you don't know if you will want to use it in a future view. Your user did add and then later remove that item from the basket or at least attempt to. You may later want to use this information to remind the user of this at later date.