Event Dispatchers
Domain event and integration event dispatching.
IDomainEventDispatcher
Dispatches domain events to handlers after SaveChanges.
| Method | Description |
|---|---|
| DispatchAsync(DomainEvent, CancellationToken) | Dispatch single event |
| DispatchAsync(IEnumerable<DomainEvent>, CancellationToken) | Dispatch multiple |
IEventBus
Publishes integration events across services.
| Method | Description |
|---|---|
| PublishAsync<TEvent>(TEvent, CancellationToken) | Publish to default topic |
| PublishAsync<TEvent>(string topic, TEvent, CancellationToken) | Publish to specific topic |
Usage
csharp
public class OrderCompletedEventHandler : INotificationHandler<OrderCompletedEvent>
{
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).