Skip to content

Instantly share code, notes, and snippets.

@tjaskula
Last active April 26, 2018 10:44
Show Gist options
  • Save tjaskula/845493cd4e3c65711e959cb4da03e37b to your computer and use it in GitHub Desktop.
Save tjaskula/845493cd4e3c65711e959cb4da03e37b to your computer and use it in GitHub Desktop.
dddx code samles
public class CustomerRepository : IRepository
{
public CustomerRepository(IDataStore dataStore, IEventDispatcher eventDispatcher)
{
// boilerplate initialization ....
}
public Persist(Customer customer)
{
this.dataStore.Save(customer);
this.eventDispatcher.Dispatch(customer.RecordedEvents());
}
}
// Returning events
var dispatcher = new DomainEventsDispatcher();
var customer = new Customer();
customer.MakePreferredCustomer();
dispatcher.Dispatch(customer.RecordedEvents());
// Double dispatch
public class Customer
{
public void MakePreferredCustomer(IEventDispatcher dispatcher)
{
dispartcher.Raise(new CustomerBecamePreferred() { Customer = this });
}
}
// Udi Dahan's style
public class Customer
{
public void MakePreferredCustomer()
{
DomainEvents.Raise(new CustomerBecamePreferred() { Customer = this });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment