public VersionConsistencyException(ResourceInfo resource, MutationEvent mutation, ulong aggregateVersion) : base($"Версия агрегата для ресурса {resource.ToFullString()} {aggregateVersion} не соответствует базовой версии для события ${mutation}") { Resource = resource; Mutation = mutation; AggregateVersion = aggregateVersion; }
private void ApplyMutation(MutationEvent mutation) { var version = Version; State = ApplyMutation(State, mutation, ref version); Version = version; }
public void Mutate(MutationEvent mutation) { mutation.BaseVersion = Version; ApplyMutation(mutation); if (Guid.Empty.Equals(mutation.Id)) { repo.PushEvent(Resource, mutation); OnMutationEventPushed?.Invoke(mutation); } }
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); }