Skip to content

Instantly share code, notes, and snippets.

@JefClaes
Last active August 29, 2015 13:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JefClaes/8975968 to your computer and use it in GitHub Desktop.
Save JefClaes/8975968 to your computer and use it in GitHub Desktop.
Domain Event flavours
// Udi style w Static Domain Events
var dispatcher = new RecordingDomainEventsDispatcher();
DomainEvents.Dispatcher = dispatcher;
var customer = new Customer(new Address());
customer.Move(new Address());
Console.WriteLine("Customer moved: " + dispatcher.RecordedDomainEvent(new CustomerMoved()));
Console.ReadLine();
// Double Dispatch
var dispatcher = new RecordingDomainEventsDispatcher();
var customer = new Customer(new Address());
customer.Move(new Address(), dispatcher);
Console.WriteLine("Customer moved: " + dispatcher.RecordedDomainEvent(new CustomerMoved()));
Console.ReadLine();
// Return domain events
http://www.jayway.com/2013/06/20/dont-publish-domain-events-return-them/
// Aggregates are responsible for recording, dispatcher is called higher up the chain
var dispatcher = new RecordingDomainEventsDispatcher();
var customer = new Customer(new Address());
customer.Move(new Address());
dispatcher.Dispatch(customer.RecordedEvents());
Console.WriteLine("Customer moved: " + dispatcher.RecordedDomainEvent(new CustomerMoved()));
Console.ReadLine();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment