void IEventStore.SaveEvents(ItemIdentity aggregateId, IEnumerable <Event> events, int expectedVersion) { List <EventDescriptor> eventDescriptors; // try to get event descriptors list for given aggregate id // otherwise -> create empty dictionary if (!_current.TryGetValue(aggregateId, out eventDescriptors)) { eventDescriptors = new List <EventDescriptor>(); _current.Add(aggregateId, eventDescriptors); } // check whether latest event version matches current aggregate version // otherwise -> throw exception else if (eventDescriptors[eventDescriptors.Count - 1].Version != expectedVersion && expectedVersion != -1) { throw new ConcurrencyException(); } var i = expectedVersion; // iterate through current aggregate events increasing version with each processed event foreach (var @event in events) { i++; @event.Version = i; // push event to the event descriptors list for current aggregate eventDescriptors.Add(new EventDescriptor(aggregateId, @event, i)); // publish current event to the bus for further processing by subscribers _publisher.Publish(@event); } }
void IEventStore.SaveEvents(ItemIdentity aggregateId, IEnumerable<Event> events, int expectedVersion) { List<EventDescriptor> eventDescriptors; // try to get event descriptors list for given aggregate id // otherwise -> create empty dictionary if (!_current.TryGetValue(aggregateId, out eventDescriptors)) { eventDescriptors = new List<EventDescriptor>(); _current.Add(aggregateId, eventDescriptors); } // check whether latest event version matches current aggregate version // otherwise -> throw exception else if (eventDescriptors[eventDescriptors.Count - 1].Version != expectedVersion && expectedVersion != -1) { throw new ConcurrencyException(); } var i = expectedVersion; // iterate through current aggregate events increasing version with each processed event foreach (var @event in events) { i++; @event.Version = i; // push event to the event descriptors list for current aggregate eventDescriptors.Add(new EventDescriptor(aggregateId, @event, i)); // publish current event to the bus for further processing by subscribers _publisher.Publish(@event); } }
public T GetId(ItemIdentity identity) { var obj = new T();//lots of ways to do this var e = _storage.GetEventsForAggregate(identity); obj.LoadsFromHistory(e); return(obj); }
List <Event> IEventStore.GetEventsForAggregate(ItemIdentity aggregateId) { List <EventDescriptor> eventDescriptors; if (!_current.TryGetValue(aggregateId, out eventDescriptors)) { throw new AggregateNotFoundException(); } return(eventDescriptors.Select(desc => desc.EventData).ToList()); }
List<Event> IEventStore.GetEventsForAggregate(ItemIdentity aggregateId) { List<EventDescriptor> eventDescriptors; if (!_current.TryGetValue(aggregateId, out eventDescriptors)) { throw new AggregateNotFoundException(); } return eventDescriptors.Select(desc => desc.EventData).ToList(); }
public EventDescriptor(ItemIdentity id, Event eventData, int version) { Id = id; EventData = eventData; Version = version; }
public InventoryItemDeactivated(ItemIdentity id) : base(id) { }
public ItemCreatedEvent(ItemIdentity id) { Id = id; }
public InventoryItemRenamed(ItemIdentity id,string name) { Name = name; }
public ItemsCheckedInToInventory(ItemIdentity id, int count) { Count = count; }
public AggregateRoot(ItemIdentity id) { Id = id; }
public InventoryItemCreated(ItemIdentity id,string name) :base(id) { }