何时使用域事件与双重调度

发布于 2024-10-15 12:11:15 字数 227 浏览 10 评论 0原文

我对何时使用域事件以及何时使用双重调度感到困惑。 Udi鼓励我们使用领域事件来维护模型的封装性并远离贫血设计,但在我看来,领域事件只能在操作执行或突然结束后使用,而不是在操作正在进行时使用。

例如:在解决一些业务逻辑时,我需要访问存储库,然后根据值,我可以引发域事件。但问题是模型在解决业务逻辑时如何访问存储库,这里我认为我们可以使用双重调度

请告诉我,上述说法是否有效?

I am confused with when to use domain events and when to use double dispatch. Udi encourages us to use domain events to maintain encapsulation of model and away from anemic design, but in my opinion domain events can only be used after the operation has been performed or ended abruptly, not at the time when the operation is in progress.

For example: while solving some business logic I need to access the repository, and then based on the value, I can raise domain events. But the question is how the model can access repository at the time of solving business logic, here in my opinion we could use double dispatch.

Please tell me, are the above statements are valid or not?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墟烟 2024-10-22 12:11:15

有很多 谈论这个

我个人同意 Szymon Pobiega 的观点:

我自己的经验法则是,当可以进行单向交互时,使用领域事件(如 Udi 所描述)作为 IoC 的首选方式。如果不能,我使用双重调度。


例如 -:在解决一些业务逻辑时,我需要访问存储库,然后根据值,我可以引发域事件。

您的聚合根应该包含执行操作所需的所有内容。在做某事时不应该需要存储库。聚合根划定了事务边界。

There's been quite much talking about this.

I personally aggree with Szymon Pobiega:

My own rule of thumb is use Domain Events (as desscribed by Udi) as a preferred way of IoC when interaction can be made one-way. If it can't, I use double dispatch.


For eg -: while solving some business logic i need to access repository, and then based on value, i can raise domain events.

Your aggregate root should contain everything You need to perform operation. There shouldn't be a need for repository while doing something. Aggregate root draws transactional boundaries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文