Table of Contents

Interface IDomainEventPublisher

Namespace
Trellis.Mediator
Assembly
Trellis.Mediator.dll

Publishes a single IDomainEvent by resolving and invoking all IDomainEventHandler<TEvent> registrations for the event's runtime type.

public interface IDomainEventPublisher
Extension Methods

Remarks

The framework's DomainEventDispatchBehavior<TMessage, TResponse> uses this contract to dispatch events from an aggregate after a successful command. Application code rarely needs to call this directly; injecting the publisher is useful only for non-pipeline contexts such as background jobs or scheduled tasks that want to fan out an event the same way the pipeline would.

Implementations are expected to be best-effort: non-cancellation handler exceptions are logged and swallowed so that one handler's failure does not block the others. OperationCanceledException matching the supplied cancellation token is the one exception that propagates so the originating request can abort cleanly.

Swallowing is correct here because this contract's callers dispatch post-commit and have no retry mechanism. Callers that do own one — principally the transactional outbox relay, which can re-drain a row with backoff — use IReportingDomainEventPublisher instead, which reports per-handler outcomes so only the failed handlers are retried.

Methods

PublishAsync(IDomainEvent, CancellationToken)

Publishes the specified domain event to all matching handlers.

ValueTask PublishAsync(IDomainEvent domainEvent, CancellationToken cancellationToken)

Parameters

domainEvent IDomainEvent

The event to publish. Resolution uses domainEvent.GetType().

cancellationToken CancellationToken

A token to observe while waiting on the handlers.

Returns

ValueTask

A ValueTask that completes when all handlers have run (or thrown).