Skip to content

Domain Events

Marc Wittke edited this page Sep 29, 2018 · 1 revision

A domain event is something that just happened. Someone else is reacting to this event in the same logical transaction. If the handling of any domain event fails, the whole action is considered as failing and the transaction must be rolled back.

IDomainEventAggregator

Channels events from multiple objects into a single object to simplify registration for clients. See https://martinfowler.com/eaaDev/EventAggregator.html for more details.

Notice that RaiseEvents() is called at the end of a unit of work, just before the transaction is to be committed and all transient changes have been written to the persistence store. There is no guaranteed order of handling events.

public interface IDomainEventAggregator
{
    void PublishDomainEvent<TDomainEvent>(TDomainEvent domainEvent) where TDomainEvent : IDomainEvent;
    void RaiseEvents();
}

The built-in implementation DomainEventHandler should be all you need in most cases.

Clone this wiki locally