How are domain events used to enforce consistency?

How are domain events used to enforce consistency?

Domain events to enforce consistency between multiple aggregates within the same domain Figure 7-14 shows how consistency between aggregates is achieved by domain events. When the user initiates an order, the Order Aggregate sends an OrderStarted domain event.

How are domain events handled in order aggregate?

When the user initiates an order, the Order Aggregate sends an OrderStarted domain event. The OrderStarted domain event is handled by the Buyer Aggregate to create a Buyer object in the ordering microservice, based on the original user info from the identity microservice (with information provided in the CreateOrder command).

How are domain events handled in eshoponcontainers application?

For example, in the eShopOnContainers application, when an order is created, the user becomes a buyer, so an OrderStartedDomainEvent is raised and handled in the ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler, so the underlying concept is evident.

How are domain events similar to command handlers?

In that sense, event handlers are similar to command handlers, so both are part of the application layer. The important difference is that a command should be processed only once. A domain event could be processed zero or n times, because it can be received by multiple receivers or event handlers with a different purpose for each handler.

How many times can a domain event be processed?

A domain event could be processed zero or n times, because it can be received by multiple receivers or event handlers with a different purpose for each handler. Having an open number of handlers per domain event allows you to add as many domain rules as needed, without affecting current code.

How are domain events and integration events the same?

Semantically, domain and integration events are the same thing: notifications about something that just happened. However, their implementation must be different. Domain events are just messages pushed to a domain event dispatcher, which could be implemented as an in-memory mediator based on an IoC container or any other method.