Created
January 13, 2018 19:43
-
-
Save horsdal/e90954414f32299d1f500477ece02024 to your computer and use it in GitHub Desktop.
This file contains 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 Aggregate<T> where T : Aggregate<T> | |
{ | |
private readonly List<Event<T>> newEvents = new List<Event<T>>(); | |
public Guid Id { get; protected internal set; } | |
public IEnumerable<Event<T>> NewEvents => this.newEvents.AsReadOnly(); | |
public void Replay(List<Event<T>> events) | |
{ | |
foreach (var @event in events) | |
Play(@event); | |
} | |
internal void Emit(Event<T> @event) | |
{ | |
this.newEvents.Add(@event); | |
Play(@event); | |
} | |
private void Play(Event<T> @event) | |
{ | |
@event.When(this as T); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment