Beispiel #1
0
        private IDomainEvent Transform(EventStoreRecord record)
        {
            var data = JsonConvert.DeserializeObject(record.Data, _jsonSettings);
            var evt  = data as IDomainEvent;

            return(evt);
        }
Beispiel #2
0
        public async Task SaveAsync(IEntityId aggregateId, int originatingVersion, IReadOnlyCollection <IDomainEvent> events, string aggregateName, CancellationToken cancellationToken)
        {
            if (!events.Any())
            {
                return;
            }

            var records = events.Select(evt => EventStoreRecord.CreateRecord(
                                            recordId: Guid.NewGuid(),
                                            serializedData: JsonConvert.SerializeObject(evt, Formatting.Indented, _jsonSettings),
                                            version: ++originatingVersion,
                                            createdAt: evt.CreatedAt,
                                            domainEventName: evt.GetType().Name,
                                            aggregateName: aggregateName,
                                            aggregateRootId: aggregateId.ToString()
                                            ));

            await _dbContext.EventStoreRecords.AddRangeAsync(records, cancellationToken);

            await _dbContext.SaveChangesAsync(cancellationToken);
        }