Skip to content

Instantly share code, notes, and snippets.

@horsdal
Created January 13, 2018 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save horsdal/e90954414f32299d1f500477ece02024 to your computer and use it in GitHub Desktop.
Save horsdal/e90954414f32299d1f500477ece02024 to your computer and use it in GitHub Desktop.
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