Table of Contents

Class IntegrationEventDispatchServiceCollectionExtensions

Namespace
Trellis.Mediator
Assembly
Trellis.Mediator.dll

Extension methods for registering Trellis.Mediator integration-event publishing.

public static class IntegrationEventDispatchServiceCollectionExtensions
Inheritance
IntegrationEventDispatchServiceCollectionExtensions
Inherited Members

Remarks

Unlike domain-event dispatch, integration events are not dispatched by a command-pipeline behavior; they are produced via the IIntegrationEventCollector during domain-event handling and published by the transactional outbox relay. These helpers register the default in-process publisher, the scoped collector, and any in-process consumers.

Methods

AddIntegrationEventDispatch(IServiceCollection)

Registers the default IIntegrationEventPublisher (in-process fan-out) and the scoped IIntegrationEventCollector. This is the AOT/trim-friendly entry point; pair it with AddIntegrationEventHandler<TEvent, THandler>(IServiceCollection) for each consumer.

public static IServiceCollection AddIntegrationEventDispatch(this IServiceCollection services)

Parameters

services IServiceCollection

The service collection.

Returns

IServiceCollection

The service collection for chaining.

Remarks

Idempotent: calling this more than once registers the publisher and collector exactly once. To deliver integration events to other services, replace the IIntegrationEventPublisher registration with a message-broker adapter after calling this method.

AddIntegrationEventDispatch(IServiceCollection, params Assembly[])

Scans the specified assemblies for concrete IIntegrationEventHandler<TEvent> implementations and registers each as a scoped service, along with the default publisher and collector.

[RequiresUnreferencedCode("Assembly scanning requires unreferenced types. Use AddIntegrationEventHandler<TEvent, THandler> for AOT/trim scenarios.")]
[RequiresDynamicCode("Constructs closed generic IIntegrationEventHandler<TEvent> at runtime.")]
public static IServiceCollection AddIntegrationEventDispatch(this IServiceCollection services, params Assembly[] assemblies)

Parameters

services IServiceCollection

The service collection.

assemblies Assembly[]

Assemblies to scan for handler implementations.

Returns

IServiceCollection

The service collection for chaining.

Exceptions

ArgumentException

Thrown when assemblies is empty or contains a null element.

AddIntegrationEventHandler<TEvent, THandler>(IServiceCollection)

Registers a single IIntegrationEventHandler<TEvent> and ensures the publisher and collector are wired up. Use this for AOT/trim scenarios where assembly scanning is not available.

public static IServiceCollection AddIntegrationEventHandler<TEvent, THandler>(this IServiceCollection services) where TEvent : IIntegrationEvent where THandler : class, IIntegrationEventHandler<TEvent>

Parameters

services IServiceCollection

The service collection.

Returns

IServiceCollection

The service collection for chaining.

Type Parameters

TEvent

The integration event type the handler responds to.

THandler

The handler implementation type.