Table of Contents

Class TrackedAggregateDomainEventDispatchServiceCollectionExtensions

Namespace
Trellis.Mediator
Assembly
Trellis.Mediator.dll
public static class TrackedAggregateDomainEventDispatchServiceCollectionExtensions
Inheritance
TrackedAggregateDomainEventDispatchServiceCollectionExtensions
Inherited Members

Methods

AddTrackedAggregateDomainEventDispatch(IServiceCollection)

Registers TrackedAggregateDomainEventDispatchBehavior<TMessage, TResponse> as an open-generic pipeline behavior together with the default IDomainEventPublisher implementation. The behavior auto-dispatches domain events from every aggregate the unit of work tracked at commit time, irrespective of the command's response shape.

public static IServiceCollection AddTrackedAggregateDomainEventDispatch(this IServiceCollection services)

Parameters

services IServiceCollection

The service collection.

Returns

IServiceCollection

The service collection for chaining.

Remarks

The opt-in REPLACES any registered DomainEventDispatchBehavior<TMessage, TResponse> to prevent double-dispatch on Result<TAggregate> handlers (which the response-shape behavior would also drain). Subsequent AddDomainEventHandler<TEvent, THandler>(IServiceCollection) calls remain safe: the underlying AddDomainEventDispatch registration skips the response-shape append when the tracked behavior is already present.

Pipeline ordering. Inserted as the innermost of the always-on Trellis behaviors, running after ValidationBehavior (Exception → Tracing → Logging → AuthorizationContext → static/direct/via authorization → Validation → TrackedAggregateDispatch). If TransactionalCommandBehavior (from Trellis.Mediator) is already registered, this method temporarily yanks it, ensures the always-on Trellis behaviors are present, appends tracked dispatch, and re-appends the transactional behavior as innermost. The result is order-independent: events fire after the transaction commits regardless of whether AddTrellisUnitOfWork<TContext>() was called before or after this method.

Resolution requirement. The behavior resolves ITrackedAggregateSource at construction time. AddTrellisUnitOfWork<TContext>() registers the EF Core forwarder; consumers using a custom IUnitOfWork must either ensure it implements ITrackedAggregateSource (the forwarder casts through it) or register ITrackedAggregateSource explicitly. Resolution throws InvalidOperationException if the requirement is not met.

Idempotent: calling this method more than once registers the behavior and publisher exactly once.

Exceptions

ArgumentNullException

Thrown when services is null.