public void ApplyEvent <TEvent>(TEvent @event) where TEvent : EventBase { try { AggregateReflectionHelper.Apply(this, @event); } catch (Exception e) { //TODO: handle } Version++; _uncommitedEvents.Add(new UncommittedEvent(Version, @event)); }
public void Load(List <CommittedEvent> events) { if (CommittedEvents?.Any() ?? false) { throw new Exception("Aggregate already loaded."); } foreach (var committedEvent in events) { AggregateReflectionHelper.Apply(this, committedEvent.Event); } CommittedEvents = events; Version = events.Any() ? events.Max(e => e.Version) : -1; }