Search code examples
domain-driven-designterminologydomain-events

Does application event term exist in DDD?


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.


Solution

  • 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.