CQRS/EventStore - 更改两个聚合
我有一个更新两个聚合的命令。由于聚合路由是事务边界,因此我有一个命令对第一个聚合执行repository.Save() 操作,然后我触发另一个命令(从第一个命令内),该命令作用于第二个聚合。每个 Save() 操作都会启动其事件存储事务并提交更改,然后发布它们。
首先,这是否正确,即让一个命令通过另一个命令通知另一个聚合?
我在 Mark Nihjof 的代码中注意到他使用事件处理程序,这很好,因为您可以将事件处理程序注册到同一事件。我尝试使用 J Oliver 的事件存储来执行此操作,但 IDispatchCommit 中的 commits.events 在处理第二个聚合值时引用第一个聚合值。这导致了一些奇怪的错误。
那么我应该找到一种方法来使用 EventHandlers 来完成这项工作,或者在命令中触发命令好吗?
JD
编辑 - 我已经将我的线路切换为使用 .UsingAsynchronousDispatchScheduler() ,现在允许注册事件触发多个事件处理程序,这反过来会在另一个聚合上触发命令,它似乎工作。那么,这是正确的方法吗?而不是使用命令触发命令?
I have a command that updates two aggregates. Since aggregate routes are transactional boundaries, I have a command that does a repository.Save() action on the first aggregate and then I fire another command (from within the first command) which acts on the second aggregate. Each Save() actions starts its Event-Store transaction and commits the changes and then publishes them.
First is this correct, i.e. letting one command notify another aggregate via another command?
I noticed in Mark Nihjof's code that he uses event handlers which is nice as you could register the event handlers to the same event. I tried doing this using J Oliver's Event-Store but my commits.events in IDispatchCommit were referencing the first aggregates values when processing the second. This caused some weird errors.
So should I find a way of making this work with EventHandlers or is firing off commands within commands okay?
JD
Edit - I have used switched my wire up to use .UsingAsynchronousDispatchScheduler() and am now allowing registered events to fire more than one event handler which in turn fires a command on the other aggregate and it seems to work. So, is this the correct way to do it and not use commmands firing commands?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为剥这只猫的皮有一百万零一种方法。我不确定从事件处理程序触发命令是否可行,在这种情况下我必须命令处理程序响应相同的命令。
我确实发现 documently 非常适合参考应用程序。你看过那个吗?
I think there's a million and one ways to skin this cat. I'm not sure firing a command from an event handler is the way to go, I have to command handlers respond to the same command in this instance.
I do find documently good for a reference app. Have you looked a that?