Skip to content

Event Dispatchers

Domain event and integration event dispatching.

IDomainEventDispatcher

Dispatches domain events to handlers after SaveChanges.

MethodDescription
DispatchAsync(DomainEvent, CancellationToken)Dispatch single event
DispatchAsync(IEnumerable<DomainEvent>, CancellationToken)Dispatch multiple

IEventBus

Publishes integration events across services.

MethodDescription
PublishAsync<TEvent>(TEvent, CancellationToken)Publish to default topic
PublishAsync<TEvent>(string topic, TEvent, CancellationToken)Publish to specific topic

Usage

csharp
public class OrderCompletedEventHandler : INotificationHandler&lt;OrderCompletedEvent&gt;
{
    private readonly IEventBus _eventBus;

    public async Task Handle(OrderCompletedEvent notification, CancellationToken ct)
    {
        // Publish integration event to other services
        await _eventBus.PublishAsync(new OrderCompletedIntegrationEvent(
            notification.OrderId,
            notification.OccurredOn
        ), ct);
    }
}

Integration

Domain events are published in-process via MediatR. Integration events go to message brokers (RabbitMQ, Azure Service Bus).

Released under the MIT License.