Transition - is a way to group a number of modifications (events) for **one** Stream (usually Aggregate Root) in one atomic package, that can be either canceled or persisted by Event Store.
 public void AppendToStream(string id, int originalVersion, ICollection<IEvent> events)
 {
     var stream = OpenStream(id);
     var transitionEvents = new List<TransitionEvent>();
     foreach (var e in events)
     {
         e.Metadata.StoredDate = DateTime.UtcNow;
         e.Metadata.TypeName = e.GetType().Name;
         transitionEvents.Add(new TransitionEvent(e.GetType().AssemblyQualifiedName, e, null));
     }
     var transition = new Transition(new TransitionId(id, originalVersion + 1), DateTime.UtcNow, transitionEvents, null);
     stream.Write(transition);
     _eventBus.Publish(events);
 }
Пример #2
0
        public void Write(Transition transition)
        {
            if (_readStarted)
                throw new InvalidOperationException("You cannot write to stream once you read from it. Open another stream.");

            try
            {
                _transitionRepository.SaveTransition(transition);
            }
            catch (DuplicateTransitionException e)
            {
                if (e.VersionId > 1)
                {
                    throw new ConcurrencyException("Transition with same Version was saved before.");
                }

                throw;
            }
        }
 public void SaveTransition(Transition transition)
 {
     _transitions.Add(transition);
 }