Exemple #1
0
        public void Store(AggregateBase aggregate)
        {
            // Take non-persisted events and write them to the event store
            var events = aggregate.GetUncommittedEvents().ToArray();

            store.AppendStream(aggregate.Id, aggregate.Version, events);

            // Once succesfully persisted, clear events from list of uncommitted events
            aggregate.ClearUncommittedEvents();
        }
        public async Task SaveAggregate(TAggregateRoot aggregate)
        {
            if (!aggregate.HasChanges())
            {
                return;
            }

            var streamId = GetStreamId(aggregate.AggregateId);
            var changes  = aggregate.GetChanges();

            if (aggregate.AggregateIsNotPersisted())
            {
                await _eventStore.CreateStream(streamId, changes);
            }
            else
            {
                await _eventStore.AppendStream(streamId, changes, aggregate.AggregateVersion);
            }
        }