DDD中是否存在应用程序事件术语? [英] Does exist application event term in DDD?

查看:81
本文介绍了DDD中是否存在应用程序事件术语?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

域事件在DDD中是众所周知的,可以在Aggregate Roots或Domain Services中发布.我的问题是,可以在应用程序服务/用例中发布域事件吗?

例如,简化.我有一个名为 UseCaseA 的应用程序服务,该服务执行调用某些聚合根的各种操作.如果要在此用例结束时引发事件,是否可以在此应用程序服务中发布 UseCaseAFinished 事件?这是一个域事件还是我们应该将其称为应用程序事件?DDD中是否存在应用程序事件术语?

谢谢.

解决方案

我认为您应该从另一个角度看待这个问题.让我解释.

与其将事件作为您的UseCaseA的结果来处理副作用,例如发送电子邮件,您要引发的事件应该仍然是您所描述的Domain Event,而不是作为事件来处理您的副作用.

然后,在处理此特定的域事件时,您可以引发一个应用程序事件"(我称它们为集成事件"),然后该事件将处理发送电子邮件,进行监视和记录的副作用.>

此集成事件可以跨越多个BC,服务甚至应用程序.

分步流程示例:

  1. 开始执行UseCaseA
  2. 对实体执行操作,更改状态等.
  3. 从域引发域事件
  4. 在执行UseCaseA结束之前分派域事件
  5. 在一个或多个域事件处理程序中捕获域事件
  6. 在其中一个处理程序中,引发一个集成事件以处理应用程序范围内"的副作用
  7. 在Integration Event Handler中处理集成事件,并发送电子邮件,进行日志记录,通知监视等.

可以通过多种方式调度集成事件,但通常是通过某种事件总线来调度.

Domain events are well known in DDD, which can be published in Aggregate Roots or in Domain Services. My question here is, Can domain events be published in application services/use cases?

For example, simplifying. I have an application service called UseCaseA, which performs various operations calling some aggregate roots. If I want to raise an event when this use case ends, could I publish the UseCaseAFinished event within this application service? Is it a domain event or should we call it an application event? Does exist application event terminology in DDD?

Thanks in advance.

解决方案

I think you should look this from another perspective. Let me explain.

Instead of raising an event as an outcome of your UseCaseA to handle your side effects, such as sending an email the event you want to raise should still be a Domain Event like you described.

Then at the time of handling this specific Domain Event you could raise an "Application event" (I'd call them Integration Events) which would then handle the side effect of sending an email, doing monitoring, logging..

This integration event can span multiple BCs, services and even applications.

Step-by-step flow example:

  1. Start executing UseCaseA
  2. Perform operations on entities, change state etc.
  3. Raise a domain event from the domain
  4. Dispatch the domain event just before the end of executing UseCaseA
  5. Catch the domain event in one or more Domain Event Handlers
  6. In one of those handlers, raise an Integration Event to handle "application wide" side-effects
  7. Handle integration event in Integration Event Handler and send emails, do logging, notify monitoring etc.

The integration event can be dispatched multiple ways, but usually via some sort of event bus.

这篇关于DDD中是否存在应用程序事件术语?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆