protected async Task SaveAggregateAsync(TAggregate aggregate)
        {
            IAggregateChangeset <TKey> changeset = aggregate.GetChangeset();

            foreach (IAggregateEvent <TKey> @event in changeset.Events)
            {
                await _eventStore.AddEventAsync(@event);
                await OnEventSavedAsync(@event);
            }
            changeset.Commit();
        }
예제 #2
0
        protected virtual async Task <IAggregateChangeset <TKey> > SaveAggregateAsync(TAggregate aggregate,
                                                                                      CancellationToken cancellationToken = default)
        {
            if (aggregate is null)
            {
                throw new ArgumentNullException(nameof(aggregate));
            }

            IAggregateChangeset <TKey> changeset = aggregate.GetChangeset();

            foreach (IAggregateEvent <TKey> @event in changeset.Events)
            {
                await _eventStore.AddEventAsync(@event, cancellationToken).ConfigureAwait(false);
            }

            if (changeset.Snapshot != null)
            {
                await _snapshotStore.AddSnapshotAsync(changeset.Snapshot, cancellationToken).ConfigureAwait(false);
            }

            changeset.Commit();
            return(changeset);
        }