Exemple #1
0
        protected async Task SaveAggregateAsync(TAggregate aggregate)
        {
            Aggregate.Changeset changeset = aggregate.GetChangeset();
            foreach (AggregateEvent @event in changeset.Events)
            {
                await _eventStore.AddEventAsync(@event);
            }
            changeset.Commit();

            AggregateSaved?.Invoke(this, new AggregateSavedEventArgs(changeset.Events));
        }
        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();
        }
        public async Task SaveAsync(TAggregate aggregate)
        {
            try
            {
                IEventSourced <TAggregateId> aggregateEventSourcedView = aggregate;

                foreach (var evt in aggregateEventSourcedView.UncommittedEvents)
                {
                    await _eventStore.AddEventAsync(evt).ConfigureAwait(false);

                    // TODO : create PublishEventAsync method to make this call async
                    PublishEvent(evt);
                }
                aggregateEventSourcedView.ClearUncommittedEvents();
            }
            catch (EventStoreNotReachableException ex)
            {
                throw new RepositoryException(CommunicationImpossibleWithPersistenceBackend, ex);
            }
        }
Exemple #4
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);
        }