load method

  1. @mustCallSuper
Future<TAggregate> load(
  1. TId id
)

Load AggregateState into given aggregate from this store If aggregate does not exist a AggregateNotFound is thrown.

Implementation

@mustCallSuper
Future<TAggregate> load(TId id) async {
  final aggregate = newInstance(
    id,
    await loadState(id),
  );
  final stream = StreamName.fromId(TAggregate, id);
  final next = StreamReadPosition(aggregate.originalVersion + 1);
  try {
    for (var event in await _events.readEvents(stream, next)) {
      aggregate.fold(_toDomainEvent(event));
    }
    return aggregate..commit();
  } on StreamNotFoundException catch (e) {
    throw AggregateNotFoundException(TAggregate, id, e);
  }
}