Guest User

Untitled

a guest
Jan 24th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. public abstract class Aggregate<T> where T : Aggregate<T>
  2. {
  3. private readonly List<Event<T>> newEvents = new List<Event<T>>();
  4. public Guid Id { get; protected internal set; }
  5. public IEnumerable<Event<T>> NewEvents => this.newEvents.AsReadOnly();
  6.  
  7. public void Replay(List<Event<T>> events)
  8. {
  9. foreach (var @event in events)
  10. Play(@event);
  11. }
  12.  
  13. internal void Emit(Event<T> @event)
  14. {
  15. this.newEvents.Add(@event);
  16. Play(@event);
  17. }
  18.  
  19. private void Play(Event<T> @event)
  20. {
  21. @event.When(this as T);
  22. }
  23. }
Add Comment
Please, Sign In to add comment