Exemplo n.º 1
0
        // lifetime change management
        // atomic consistency boundary of an Aggregate & its contents
        void ChangeAgg(TrustedSystemId withAggIdOf, Action <TrustedSystemAggregate> usingThisMethod)
        {
            var eventStreamId = withAggIdOf.Id.ToString();
            var eventStream   = _eventStore.LoadEventStream(eventStreamId);

            var aggStateBeforeChanges = TrustedSystemState.BuildStateFromEventHistory(eventStream.Events);

            var aggToChange = new TrustedSystemAggregate(aggStateBeforeChanges);

            // HACK
            if (eventStream.Events.Count == 0)
            {
                aggToChange.Create(withAggIdOf);
            }

            usingThisMethod(aggToChange);

            _eventStore.AppendEventsToStream(eventStreamId, eventStream.StreamVersion, aggToChange.EventsCausingChanges);
        }
Exemplo n.º 2
0
        // lifetime change management

        // atomic consistency boundary of an Aggregate & its contents

        void UpdateDomain(Action <TrustedSystemAggregate> usingThisMethod)
        {
            if (_currentSystem == null)
            {
                throw new InvalidOperationException("System ID should be provided by now");
            }

            var eventStreamId = _currentSystem.ToStreamId();
            var eventStream   = _eventStore.LoadEventStream(eventStreamId);

            var aggStateBeforeChanges = TrustedSystemState.BuildStateFromEventHistory(eventStream.Events);

            var aggToChange = new TrustedSystemAggregate(aggStateBeforeChanges);


            usingThisMethod(aggToChange);

            _eventStore.AppendEventsToStream(eventStreamId, eventStream.StreamVersion, aggToChange.EventsCausingChanges);
        }