EricksonLopez.Concurrency Overview
EricksonLopez.Concurrency (2.0.0 on NuGet, L2) provides optimistic concurrency verification (ExpectedVersion, ConcurrencyVersion, ConcurrencyToken), atomic compare-and-swap (ExecuteCasAsync), and multi-dialect database optimistic update helpers.
- Zero-allocation version structs:
ConcurrencyVersionandExpectedVersionarereadonly record structprimitives with checked version progression (Next()). - Atomic CAS with non-reentrancy guards (
v2.0.0):IConcurrencyController.ExecuteCasAsyncenforces mandatory version advancement (IMutableVersionedEntityor new version) and fails fast on reentrant calls viaAsyncLocal. - Single-row optimistic SQL verification:
ExecuteOptimisticAsyncverifies affected-row counts strictly and maps dialect conflict conditions (Deadlock,LockUnavailable,AlreadyExists) to structuredConcurrencyConflictdescriptors. - Explicit Result integration:
EricksonLopez.Concurrency.ResultconvertsCasResult<TEntity>cleanly toResult<TEntity>without throwing exceptions for conflict branches.
Rendering diagram…
flowchart LR Ent["IVersionedEntity"] --> Ctrl["IConcurrencyController.ExecuteCasAsync"] Ctrl -- Version Mismatch --> Conf["CasResult Conflict / ConcurrencyConflict"] Ctrl -- Match --> Mut["Mutate & Advance Version"] Mut --> Ok["CasResult Success -> .ToResult()"]
View accessible text summary and structure
A versioned entity enters IConcurrencyController.ExecuteCasAsync with an ExpectedVersion, checks the version guard, applies the mutation, and outputs CasResult<TEntity> or ConcurrencyConflict.
flowchart LR
Ent["IVersionedEntity"] --> Ctrl["IConcurrencyController.ExecuteCasAsync"]
Ctrl -- Version Mismatch --> Conf["CasResult Conflict / ConcurrencyConflict"]
Ctrl -- Match --> Mut["Mutate & Advance Version"]
Mut --> Ok["CasResult Success -> .ToResult()"]Package Roster & Native AOT Status (13 / 13 Published)
Section titled “Package Roster & Native AOT Status (13 / 13 Published)”All 13 packages are published at 2.0.0 on NuGet (4,167 total downloads; localVersion: 3.1.0 on disk), target net8.0;net9.0;net10.0, and achieve Full AOT status (13/13 IsAotCompatible=true, EnableTrimAnalyzer=true):
- Core & Abstractions:
EricksonLopez.Concurrency(393dl),EricksonLopez.Concurrency.Abstractions(634dl). - Web, Mediator & Result:
EricksonLopez.Concurrency.AspNetCore(277dl),EricksonLopez.Concurrency.Mediator(298dl),EricksonLopez.Concurrency.Result(263dl),EricksonLopez.Concurrency.Testing(274dl). - Persistence & Dialects:
EricksonLopez.Concurrency.Dapper(337dl),EricksonLopez.Concurrency.PostgreSql(296dl),EricksonLopez.Concurrency.MariaDb(283dl),EricksonLopez.Concurrency.MySql(284dl),EricksonLopez.Concurrency.SqlServer(280dl),EricksonLopez.Concurrency.Sqlite(279dl),EricksonLopez.Concurrency.Oracle(269dl).
Measured directly from BenchmarkDotNet.Artifacts (54 total rows: 18 measured on .NET 10.0.12 X64 RyuJIT x86-64-v3, AMD EPYC 7763; 36 na_error rows on .NET 8.0/.NET 9.0 excluded; no NativeAOT reports):
TokenAllocationBenchmarks.CreateStructVersion: 0.0002 ns / 0 BConcurrencyBenchmarks.DirectVersionComparison: 0.135 ns / 0 BConcurrencyBenchmarks.CheckerCheckVersion: 0.5336 ns / 0 BConcurrencyBenchmarks.ResultConversion: 3.4445 ns / 0 BConcurrencyBenchmarks.CheckerCheckToken: 22.8653 ns / 64 BConcurrencyBenchmarks.ControllerExecuteCasAsync: 182.1842 ns / 0 BOptimisticContentionBenchmarks.SingleWorkerUncontendedCas: 201.6 ns / 48 BOptimisticContentionBenchmarks.ParallelContentionFourWorkers: 2,629.2 ns / 976 B