public VersionConsistencyException(ResourceInfo resource, MutationEvent mutation, ulong aggregateVersion)
     : base($"Версия агрегата для ресурса {resource.ToFullString()} {aggregateVersion} не соответствует базовой версии для события ${mutation}")
 {
     Resource         = resource;
     Mutation         = mutation;
     AggregateVersion = aggregateVersion;
 }
Ejemplo n.º 2
0
        private void ApplyMutation(MutationEvent mutation)
        {
            var version = Version;

            State   = ApplyMutation(State, mutation, ref version);
            Version = version;
        }
Ejemplo n.º 3
0
 public void Mutate(MutationEvent mutation)
 {
     mutation.BaseVersion = Version;
     ApplyMutation(mutation);
     if (Guid.Empty.Equals(mutation.Id))
     {
         repo.PushEvent(Resource, mutation);
         OnMutationEventPushed?.Invoke(mutation);
     }
 }
Ejemplo n.º 4
0
        private TState ApplyMutation(TState state, MutationEvent mutation, ref ulong version)
        {
            if (mutation.BaseVersion != version)
            {
                throw new VersionConsistencyException(Resource, mutation, version);
            }

            var newState = (TState)((dynamic)this).Apply(State, (dynamic)mutation);

            version++;
            return(newState);
        }