Skip to content

Instantly share code, notes, and snippets.

@tjaskula
Forked from JefClaes/gist:8975968
Last active August 29, 2015 14:07
Show Gist options
  • Save tjaskula/8236ed434e20a6fc143a to your computer and use it in GitHub Desktop.
Save tjaskula/8236ed434e20a6fc143a to your computer and use it in GitHub Desktop.
// 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