Skip to content

Domain Event Dispatching ​

IDomainEventDispatcher is an in-process contract for dispatching domain events to handlers. It does not provide a message broker or durable delivery.

Dispatcher contract ​

MethodDescription
DispatchAsync(DomainEvent, CancellationToken)Dispatches one event.
DispatchAsync(IEnumerable<DomainEvent>, CancellationToken)Dispatches events in order.
DispatchAsync(IAggregateRoot, CancellationToken)Dispatches the aggregate's pending events and clears them after successful dispatch.

DomainEvent implements MediatR's INotification. The generic DomainEventDispatcher wraps each event in DomainEventNotification and publishes that wrapper through IMediator. A typed handler can derive from the existing DomainEventHandler<TDomainEvent> adapter.

Persistence and transaction boundaries ​

The generic dispatcher does not save changes or commit a transaction. In the Auth module, GrydAuthDbContext.SaveChangesAsync publishes the concrete event through MediatR and invokes authorization marker handlers inside its event loop. For relational writes, this happens before the context's transaction commits; when a caller owns the transaction, SaveChangesAsync does not commit it. A handler's successful execution is therefore not proof that the business transaction has committed. Avoid performing irreversible external effects from these handlers.

All supported Auth save overloads run this protocol; acceptAllChangesOnSuccess=false is refused. Tracked User writes also compare their original token generation. See ADR 0013 for concurrency, mutation loaders and compatibility requirements.

Notifications have their own mechanism and contract. They should not be treated as a generic guarantee that a domain event will be delivered after commit.

Integration event boundary ​

IEventBus declares publish methods, but this repository does not supply a concrete broker adapter. A host that provides an adapter must define its transport, retry, ordering, and durability semantics. The interface alone does not imply RabbitMQ, Azure Service Bus, or guaranteed delivery.

The OutboxMessage and PostgresOutbox types live under Gryd.Infrastructure.Messaging in the Infrastructure project. They are outbox primitives, not a generic IEventBus transport, and the audit write-loss counter does not constitute an audit outbox. Durable audit delivery remains a separate future capability.

Transactional producer storage ​

The transactional outbox stages a delivery envelope and versioned JSON payload in the producer's own context and transaction. It does not make this dispatcher durable or move Auth's transactional authorization handlers after commit. OutboxProcessor provides explicit local PostgreSQL consumption with transactional inbox receipts. An opt-in worker drains registered producers independently, with declared consumer waiting and a read-only operational query. Auth migration remains separate; see ADR 0012.

Released under the MIT License.