这是在 DDD 中使用领域事件的正确方法吗?
我有一个设计问题,我认为域事件可以解决,但我需要确保我以正确的方式处理它并且我正确理解域事件。
我对一个聚合根进行了更改,需要对另一个聚合根进行更改。
因此,当我在启动聚合根中进行更改时,我将触发一个域事件,该事件将在其他聚合根中应用更改。如果一切顺利,我有两个数据库事务将被持久化。
现在,如果一个失败(比如第二个),我该如何解决这个问题,或者如果第二个失败了,但我的初始更改未能持续?
我假设这是一个单用户系统,其中所有内容都是同步发生的,因此第二个聚合在第一个启动聚合之前提交。
京东
I have a design question which I think Domain events will solve but I need to make sure I am going about it the correct way and that I understand Domain events correctly.
I have a change in one aggregate root which needs to make a change in the another aggregate root.
So when I make a change in my initiating aggregate root I will fire a domain event which will apply the change in the other aggregate root. If all goes well I have two database transactions which will be persisted.
Now if one fails (say the second), how do I resolve this or if the second goes through but my initiating change fails to persist?
I am assuming this is a single user system where everything happens synchronously so the second aggregate is committed before the first initiating aggregate.
JD
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于您在应用程序中如何组织工作单元管理。在 Web 应用程序中,应该为每个请求创建工作单元,在这种情况下,您通常在 http 请求中拥有一个事务,该事务将在请求结束后提交或回滚。
当然,您可以创建两个单独的事务,但我不建议在您的网络应用程序中执行此操作。在这种情况下(如果我有这样的要求)宁愿使用消息传递架构(看看 http://www.nservicebus .com/ 或 http://masstransit-project.com/)
It depends on how you have organized Unit of Work management in your application. In web app Unit of Work should be created every request and in this case you usually have one transaction within http request, which will be committed or rolled back after end of request.
Of course you can create two separate transaction, but I do not recommend to do it inside your web app. In this case (if I would have such requirements) would rather use messaging architecture (take a look at http://www.nservicebus.com/ or http://masstransit-project.com/)