[英]DDD, Domain Services and Events
Situation: 情况:
To work with domain events, Jimmy Bogart proposed a method for storing events in aggregates. 为了处理域事件,Jimmy Bogart 提出了一种将事件存储在聚合中的方法。
This, from my point of view, is a very convenient approach. 在我看来,这是一种非常方便的方法。 However, what about the case of a domain event in the domain service? 但是,在域服务中发生域事件的情况如何?
Domain Service should not have a state (stateless). 域服务不应具有状态(无状态)。 In this case, in theory, the IDispatcher event dispatcher must be injected into the constructor of such a service. 在这种情况下,从理论上讲,必须将IDispatcher事件分派器注入此类服务的构造函数中。
Question: 题:
To avoid introducing into the domain service of the event dispatcher, the suggested alternative approaches are correct: 为了避免引入事件分配器的域服务,建议的替代方法是正确的:
Note: that post was written about five years ago. 注意:该帖子写于大约五年前。 You may want to review his more recent (and more detailed): Life Beyond Distributed Transactions: An Apostate's Implementation 您可能需要查看他的最新文章(更详细): 分布式事务后的生活:叛教者的实现
Domain Service should not have a state 域服务不应具有状态
Right - and for this reason, it is very suspicious that you would want to assign responsibility for domain events in the domain service. 正确-出于这个原因,您非常想为域服务中的域事件分配责任。
You might use a domain service to calculate events for the aggregate, but the storage would still belong to the aggregate structure itself. 您可能使用域服务来计算聚合事件,但是存储仍将属于聚合结构本身。 So that would probably look like a function (or, if you prefer, a method on the domain service) that accepts some arguments provided by the aggregate and returns events. 因此,它可能看起来像一个函数(或者,如果您愿意,则是域服务上的方法),它接受聚合提供的一些参数并返回事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.