コード例 #1
0
ファイル: EfAggregateMemento.cs プロジェクト: mishrsud/Ximo
        /// <summary>
        ///     Initializes a new instance of the <see cref="EfAggregateMemento" /> class.
        /// </summary>
        /// <param name="aggregate">The aggregate instance.</param>
        protected EfAggregateMemento(EventSourcedAggregateRoot aggregate) : this()
        {
            if (aggregate == null)
            {
                throw new ArgumentNullException(nameof(aggregate));
            }

            AggregateRootId   = aggregate.Id;
            LastEventSequence = aggregate.LastEventSequence;
            Version           = aggregate.Version;
            Payload           = JsonObjectSerializer.New().Serialize(aggregate);
        }
コード例 #2
0
        protected async Task SaveUncommittedEventsAsync(EventSourcedAggregateRoot aggregate, Guid streamId)
        {
            var created = DateTime.UtcNow;

            var uncommittedEvents = aggregate.GetUncommittedEvents()
                                    .Select((e, i) => CreateEventData(streamId, e, created, i))
                                    .ToList();

            uncommittedEvents.ForEach(e => _dbContext.Events.Add(e));
            await _dbContext.SaveChangesAsync();

            aggregate.ClearUncommittedEvents();
        }