public async Task <TAggregate> GetByIdAsync <TAggregate>(Guid id, int version = int.MaxValue) where TAggregate : IAggregate, new() { var memento = await MementoStore.GetMementoAsync(id, version); var aggregate = _factory.Build <TAggregate>(memento); await ApplyEventsAsync(id, version, aggregate); return(aggregate); }
private async Task <IAggregateRoot> LoadAggregate(ICommand command) { var aggregate = _factory.Build(command.Destination); if (aggregate is ISupportSnapshots withSnapshots) { var snapshot = await _snapshotStore.GetSnapshot(command.Destination); if (snapshot != null) { aggregate = withSnapshots.RestoreFromSnapshot(snapshot); } } await foreach (var e in _eventStore.GetEventStream(aggregate.Address)) { aggregate.Apply(e); } return(aggregate); }
public static T Build <T>(this IAggregateFactory factory, string id = null) where T : IAggregate { return((T)factory.Build(typeof(T), id ?? Guid.NewGuid().ToString())); }
private IAggregate GetAggregate <TAggregate>(IEventStream stream) { return(_aggregateFactory.Build(typeof(TAggregate), stream.StreamId)); }