Extract AggregateEvents record
ADD
WalletWasabi/EventSourcing/AggregateEvents.cs
+using System.Collections.Immutable;
+
+namespace WalletWasabi.EventSourcing
+{
+ public record AggregateEvents(long TailSequenceId, ImmutableList<WrappedEvent> Events)
+ {
+ /// <summary>
+ /// SequenceId of the last event of this aggregate
+ /// </summary>
+ public long TailSequenceId { get; init; } = TailSequenceId;
+
+ /// <summary>
+ /// Ordered list of events
+ /// </summary>
+ public ImmutableList<WrappedEvent> Events { get; init; } = Events;
+ }
+}

MODIFY
WalletWasabi/EventSourcing/InMemoryEventRepository.cs
WalletWasabi/EventSourcing/InMemoryEventRepository.cs
@@ -29,14 +29,7 @@ namespace WalletWasabi.EventSourcing
<string,
ConcurrentDictionary
// aggregateId
- <string,
- (
- // SequenceId of the last event of this aggregate
- long TailSequenceId,
-
- // Ordered list of events
- ImmutableList<WrappedEvent> Events
- )>> AggregatesEventsBatches
+ <string, AggregateEvents>> AggregatesEventsBatches
{ get; } = new();
private ConcurrentDictionary
@@ -88,7 +81,7 @@ namespace WalletWasabi.EventSourcing
var aggregateEventsBatches = AggregatesEventsBatches.GetOrAdd(aggregateType, _ => new());
var (tailSequenceId, events) = aggregateEventsBatches.GetOrAdd(
aggregateId,
- _ => (0, ImmutableList<WrappedEvent>.Empty));
+ _ => new AggregateEvents(0, ImmutableList<WrappedEvent>.Empty));
if (tailSequenceId + 1 < firstSequenceId)
{
@@ -103,8 +96,8 @@ namespace WalletWasabi.EventSourcing
// Atomically detect conflict and replace lastSequenceId and lock to ensure strong order in eventsBatches.
if (!aggregateEventsBatches.TryUpdate(
key: aggregateId,
- newValue: (lastSequenceId, newEvents),
- comparisonValue: (firstSequenceId - 1, events)))
+ newValue: new AggregateEvents(lastSequenceId, newEvents),
+ comparisonValue: new AggregateEvents(firstSequenceId - 1, events)))
{
Conflicted(); // no action
throw new OptimisticConcurrencyException(

MODIFY
WalletWasabi/Exceptions/TransientException.cs
WalletWasabi/Exceptions/TransientException.cs
@@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace WalletWasabi.Exceptions
{
/// <summary>
- /// Infrastructure or optimistic conflict exception that will be fixed when retried
+ /// Infrastructure or optimistic conflict exception that will be fixed when retried.
/// </summary>
public class TransientException : Exception
{

Extract AggregateEvents record