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 abstract class AggregateRoot | |
{ | |
private readonly List<Event> _changes = new List<Event>(); | |
public abstract Guid Id { get; } | |
public int Version { get; internal set; } | |
public IEnumerable<Event> GetUncommittedChanges() | |
{ | |
// Removed for clarity |
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
[HttpPost] | |
public ActionResult CreateCustomer(Customer customer) | |
{ | |
// Check business logic here (but no persistance) | |
if (DB.Customers.Values.ToList().Any(c => c.Name == customer.Name)) | |
{ | |
ModelState.AddModelError(string.Empty, "Duplicate Name Detected"); | |
} | |
if (!ModelState.IsValid) |
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 CustomerHandler | |
{ | |
public void Handle(CustomerCreated customer) | |
{ | |
// Do Insert | |
DB.Customers.Add(customer.Id, new Customer{Id = customer.Id, Name = customer.Name}); | |
} | |
} | |
// ###################### |
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 SimpleRouter | |
{ | |
protected Dictionary<Type, List<Action<IEvent>>> Routes; | |
public SimpleRouter() | |
{ | |
Routes = new Dictionary<Type, List<Action<IEvent>>>(); | |
} | |
public void Register<T>(Action<T> handler) where T: IEvent |
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 CustomerCreated : Event | |
{ | |
public readonly Guid AggreagteId; | |
public readonly int Version; | |
public readonly Guid UserId; | |
public readonly Guid ProcessId | |
// Other fields specific to this event | |
public CustomerCreated(Guid aggregateId, int version, Guid userId, Guid processId) |
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 CustomerSummaryDenormaliser : | |
IHandle<CustomerCreated>, | |
IHandle<OrderPlaced> | |
{ | |
private readonly CustomerSummaryDto _summaryDto; | |
public CustomerSummaryDenormaliser(CustomerSummaryDto summaryDto) | |
{ | |
_summaryDto = summaryDto; | |
} |
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
CustomerCreated(1, "Joe Blogs")); | |
OrderPlaced(1, 1, DateTime.Parse("2014-09-01")); | |
OrderPlaced(1, 2, DateTime.Parse("2014-09-02")); | |
OrderPlaced(1, 2, DateTime.Parse("2014-09-03")); | |
OrderPlaced(1, 2, DateTime.Parse("2014-09-04")); | |
OrderPlaced(1, 2, DateTime.Parse("2014-09-05")); | |
OrderPlaced(1, 2, DateTime.Parse("2014-09-06")); | |
OrderPlaced(1, 2, DateTime.Parse("2014-09-07")); | |
OrderPlaced(1, 2, DateTime.Parse("2014-09-08")); |
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 CustomerCreated : Event | |
{ | |
public readonly int Id; | |
public readonly string CustomerName; | |
public CustomerCreated(int id, string customerName) | |
{ | |
Id = id; | |
CustomerName = customerName; | |
} |
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
// UnApproved with conflict with Approved but nothing else | |
_concurrencyConflictResolver.RegisterConflictList(typeof(UnApproved), new List<Type> { typeof(Approved) }); | |
// SignInRecorded doesnt conflict with anything | |
_concurrencyConflictResolver.RegisterConflictList(typeof(SignInRecorded), new List<Type>()); |
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 interface IConcurrencyConflictResolver | |
{ | |
bool ConflictsWith(Type eventToCheck, IEnumerable<Type> previousEvents); | |
void RegisterConflictList(Type eventDefinition, List<Type> conflictsWith); | |
} | |
public class ConcurrencyConflictResolver : IConcurrencyConflictResolver | |
{ | |
private readonly Dictionary<Type, List<Type>> _conflictRegister; |
NewerOlder