简体   繁体   English

DDD 中的应用程序事件?

[英]Application Events in DDD?

This question is similar to: Does exist application event term in DDD?这个问题类似于: DDD 中是否存在应用程序事件术语? , but I don't know how to apply the explanations given there to my specific issue. ,但我不知道如何将那里给出的解释应用于我的具体问题。

I have a SearchFilmUseCase and I want to raise an event FilmSearchedEvent once it finishes its execution.我有一个SearchFilmUseCase ,我想在完成执行后引发一个事件FilmSearchedEvent Currently, the application layer is raising the event.目前,应用层正在引发事件。 The only manner in which I could raise this event from the Domain is in the FilmRepository .我可以从域中引发此事件的唯一方式是在FilmRepository中。 However, the repository is just an interface, so I can't raise any event there.但是,存储库只是一个接口,所以我不能在那里引发任何事件。

I think that raising the event at the application layer is not correct.我认为在应用层提出事件是不正确的。 How can I approach this situation?我该如何处理这种情况?

One solution could be to create a domain service to perform the search and raise the event.一种解决方案可能是创建域服务来执行搜索并引发事件。

All Domain Events must be raised from domain layer.所有领域事件都必须从领域层引发。 The best place is an aggregate root where the action should be really done.最好的地方是真正应该完成操作的聚合根。 The aggregate root could contain all the domain events that have been raised, and in the application layer you could get them and publish them to the event bus.聚合根可以包含所有已引发的域事件,并且在应用程序层中,您可以获取它们并将它们发布到事件总线。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM