private void ApplyMutation(MutationEvent mutation) { var versions = Versions; State = ApplyMutation(State, mutation, DetalizationLevel, ref versions); Versions = versions; }
public VersionConsistencyException(Resource resource, MutationEvent mutation, ulong aggregateVersion) : base($"Версия агрегата для ресурса {resource.ToFullString()} {aggregateVersion} не соответствует базовой версии для события ${mutation}") { Resource = resource; Mutation = mutation; AggregateVersion = aggregateVersion; }
public void Mutate(MutationEvent mutation) { mutation.BaseVersion = GetVersion(); ApplyMutation(mutation); if (Guid.Empty.Equals(mutation.Id)) { repo.PushEvent(Resource, mutation); } }
private TState ApplyMutation(TState state, MutationEvent mutation, byte detalizationLevel, ref List <ulong> versions) { if (mutation.DetalizationLevel > detalizationLevel) { throw new ArgumentException("Попытка применить событие с более высокой степенью детализации"); } var version = GetVersion(versions, mutation.DetalizationLevel); if (mutation.BaseVersion != version) { throw new VersionConsistencyException(Resource, mutation, version); } var newState = (TState)((dynamic)this).Apply(State, (dynamic)mutation); IncrementVersion(ref versions, mutation.DetalizationLevel); return(newState); }