Core Concepts — ExpectedVersion, ConcurrencyVersion & CAS
EricksonLopez.Concurrency separates version representation from conflict resolution and database dialect mechanics.
ConcurrencyVersion(readonly record struct): ExposesNone,Initial,From(long), and overflow-checkedNext().ExpectedVersion(readonly record struct): Provides explicit factoriesExpectedVersion.Any,ExpectedVersion.New,ExpectedVersion.Exists, andExpectedVersion.Specific(long).Default Struct Caution:
default(ExpectedVersion)evaluates toSpecific(0), notExpectedVersion.Any. Always pass an explicit factory property or method.
IVersionedEntity, IMutableVersionedEntity & CasResult<T>
Section titled “IVersionedEntity, IMutableVersionedEntity & CasResult<T>”- Implement
IVersionedEntity(long Version { get; }) on immutable records (returning a new copy withVersion = state.Version + 1), orIMutableVersionedEntity(new long Version { get; set; }) when mutating entities in place (v2.0.0requires the mutation delegate to advance the version or implementIMutableVersionedEntity). CasResult<TEntity>exposesIsSuccess,IsConflict,IsInitialized,Entity,NewVersion, andConflict.IConcurrencyAwaredeclares nullableConcurrencyToken?(v2.0.0, with non-null default tokens such asstring.Empty/"None").