Skip to content

DomainEvent

Base class for domain events with MediatR integration.

Interface: IDomainEvent

PropertyTypeDescription
IdGuidUnique event identifier
OccurredOnDateTimeWhen the event occurred

DomainEvent Class

Abstract base class that auto-generates Id and OccurredOn.

Usage

csharp
public record OrderCompletedEvent(Guid OrderId) : DomainEvent;

public record UserRegisteredEvent( Guid UserId, string Email ) : DomainEvent;

Event Handling

csharp
public class OrderCompletedEventHandler : INotificationHandler<OrderCompletedEvent>
{
    public async Task Handle(OrderCompletedEvent notification, CancellationToken ct)
    {
        // Send email, update analytics, etc.
    }
}

Dispatch

Events are dispatched by infrastructure after SaveChanges.

Released under the MIT License.