Last active
April 26, 2018 10:44
-
-
Save tjaskula/845493cd4e3c65711e959cb4da03e37b to your computer and use it in GitHub Desktop.
dddx code samles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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