Exemple #1
0
 public DynamoDbEventModel(CelebrityEventBase eventBase)
 {
     AggregateId      = eventBase.AggregateId;
     AggregateVersion = eventBase.AggregateVersion;
     Timestamp        = eventBase.Timestamp;
     Name             = eventBase.Name;
     Data             = JsonConvert.SerializeObject(eventBase);
 }
        public async Task CommitAsync(CelebrityEventBase @event, CancellationToken cancellationToken = default)
        {
            if (@event is null)
            {
                throw new ArgumentNullException(nameof(@event));
            }

            var table    = _dbContext.GetTargetTable <DynamoDbEventModel>(_configuration);
            var document = _dbContext.ToDocument(@event);

            var data = @event.AggregateVersion == 0 ? null : await table.GetItemAsync(@event.AggregateId, @event.AggregateVersion - 1, cancellationToken);

            await table.PutItemAsync(document, new PutItemOperationConfig { Expected = data }, cancellationToken);
        }