public void Save(AggregateRoot aggregate)
        {
            if (String.IsNullOrEmpty(aggregate.Id))
            {
                throw new ArgumentException("Aggregate id was not specified.");
            }

            var transition = aggregate.CreateTransition(_dataTypeRegistry);

            using (var stream = _transitionStorage.OpenStream(transition.Id.StreamId))
            {
                stream.Write(transition);
            }

            if (_eventBus != null)
            {
                _eventBus.Publish(transition.Events.Select(e => (IEvent)e.Data).ToList <IEvent>());
            }

            if (_snapshotRepository != null)
            {
                aggregate.Version += 1; // we have to increase aggregate version, because of new transition increase aggregate version
                _snapshotRepository.Save(new Snapshot(aggregate.Id, transition.Id.Version, aggregate));
            }
        }
Example #2
0
        public void Save(LegacyAggregateRoot aggregate)
        {
            if (String.IsNullOrEmpty(aggregate.Id))
            {
                throw new ArgumentException("Aggregate id was not specified.");
            }

            var transition = aggregate.CreateTransition(_dataTypeRegistry);

            using (var stream = _transitionStorage.OpenStream(transition.Id.StreamId))
            {
                stream.Write(transition);
            }

//            if (_eventBus != null)
//                _eventBus.Publish(transition.Events.Select(e => (IEvent)e.Data).ToList<IEvent>());
        }