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 it be called an application event? Does application event terminology exist 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:
The integration event can be dispatched multiple ways, but usually via some sort of event bus.