Skip to main content

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 extending DomainEvent with a typed payload:

Event with Queue Name (Optional)

You can specify a static queueName for routing events to specific queues (useful for message queue implementations):

Event Properties

Every domain event automatically has these properties:

Raising Events from Aggregates

Use addDomainEvent() inside aggregate methods to record events:

Event Bus Interface

Rich Domain provides the IDomainEventBus interface with two methods:
You implement this interface according to your infrastructure needs.

Publishing Events

From Aggregates

After persisting changes, dispatch all uncommitted events:

Direct Publishing

You can also publish events directly without aggregates:

Managing Uncommitted Events

Aggregates and entities provide methods to manage events:

Event Serialization

Events can be serialized to JSON for storage or transmission:

API Reference

DomainEvent

IDomainEventBus

Aggregate Methods