What are Domain Events?
Domain Events represent something significant that happened in your domain. They enable loose coupling between aggregates and support event-driven architectures. The Rich Domain core library provides interfaces only - you implement the event publishing mechanism according to your needs (in-memory, message queues, event streams, etc.).Creating Events
Basic Event
Events are created by extendingDomainEvent with a typed payload:
Event with Queue Name (Optional)
You can specify a staticqueueName for routing events to specific queues (useful for message queue implementations):
Event Properties
Every domain event automatically has these properties:| Property | Type | Description |
|---|---|---|
eventId | string | Unique identifier for this event occurrence |
eventName | string | Name of the event (class name) |
occurredOn | Date | When the event occurred |
payload | P | The event data (typed) |
queueName | string | Optional queue name (static property) |
Raising Events from Aggregates
UseaddDomainEvent() inside aggregate methods to record events:
Event Bus Interface
Rich Domain provides theIDomainEventBus interface with two methods: