Skip to content

Commit aeb63ba

Browse files
authored
Merge pull request #126 from neuroglia-io/fix-event-sourcing
Fix the `EventSourcingRepository` to expect stream version `-1` when attempting to add a new aggregate
2 parents ae6a1b1 + 6a26d85 commit aeb63ba

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Neuroglia.Data.Infrastructure.EventSourcing/Services/EventSourcingRepository.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ public virtual async Task<TAggregate> AddAsync(TAggregate aggregate, Cancellatio
9090
ArgumentNullException.ThrowIfNull(aggregate);
9191

9292
var events = aggregate.PendingEvents.ToList();
93-
await this.EventStore.AppendAsync(this.GetStreamIdFor(aggregate.Id), events.Select(e => e.GetDescriptor()), cancellationToken: cancellationToken).ConfigureAwait(false);
93+
await this.EventStore.AppendAsync(this.GetStreamIdFor(aggregate.Id), events.Select(e => e.GetDescriptor()), -1, cancellationToken: cancellationToken).ConfigureAwait(false);
9494

9595
aggregate.State.StateVersion = (ulong)events.Count;
9696
aggregate.ClearPendingEvents();
9797

9898
await this.StateManager.TakeSnapshotAsync(aggregate, cancellationToken).ConfigureAwait(false);
99-
if(this.Options.PublishEvents) foreach (var e in events) await this.Mediator.PublishAsync((dynamic)e, cancellationToken).ConfigureAwait(false);
99+
if (this.Options.PublishEvents) foreach (var e in events) await this.Mediator.PublishAsync((dynamic)e, cancellationToken).ConfigureAwait(false);
100100

101101
return aggregate;
102102
}

0 commit comments

Comments
 (0)