Skip to content

Search EricksonLopez.* Ecosystem

Type a library name, NuGet package ID, .NET type, or architectural concept to search across the portal.

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: ConcurrencyVersion and ExpectedVersion are readonly record struct primitives with checked version progression (Next()).
  • Atomic CAS with non-reentrancy guards (v2.0.0): IConcurrencyController.ExecuteCasAsync enforces mandatory version advancement (IMutableVersionedEntity or new version) and fails fast on reentrant calls via AsyncLocal.
  • Single-row optimistic SQL verification: ExecuteOptimisticAsync verifies affected-row counts strictly and maps dialect conflict conditions (Deadlock, LockUnavailable, AlreadyExists) to structured ConcurrencyConflict descriptors.
  • Explicit Result integration: EricksonLopez.Concurrency.Result converts CasResult<TEntity> cleanly to Result<TEntity> without throwing exceptions for conflict branches.
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()"]
Optimistic CAS Verification PipelineA versioned entity enters IConcurrencyController.ExecuteCasAsync with an ExpectedVersion, checks the version guard, applies the mutation, and outputs CasResult<TEntity> or ConcurrencyConflict.
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()"]

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 (393 dl), EricksonLopez.Concurrency.Abstractions (634 dl).
  • Web, Mediator & Result: EricksonLopez.Concurrency.AspNetCore (277 dl), EricksonLopez.Concurrency.Mediator (298 dl), EricksonLopez.Concurrency.Result (263 dl), EricksonLopez.Concurrency.Testing (274 dl).
  • Persistence & Dialects: EricksonLopez.Concurrency.Dapper (337 dl), EricksonLopez.Concurrency.PostgreSql (296 dl), EricksonLopez.Concurrency.MariaDb (283 dl), EricksonLopez.Concurrency.MySql (284 dl), EricksonLopez.Concurrency.SqlServer (280 dl), EricksonLopez.Concurrency.Sqlite (279 dl), EricksonLopez.Concurrency.Oracle (269 dl).

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 B
  • ConcurrencyBenchmarks.DirectVersionComparison: 0.135 ns / 0 B
  • ConcurrencyBenchmarks.CheckerCheckVersion: 0.5336 ns / 0 B
  • ConcurrencyBenchmarks.ResultConversion: 3.4445 ns / 0 B
  • ConcurrencyBenchmarks.CheckerCheckToken: 22.8653 ns / 64 B
  • ConcurrencyBenchmarks.ControllerExecuteCasAsync: 182.1842 ns / 0 B
  • OptimisticContentionBenchmarks.SingleWorkerUncontendedCas: 201.6 ns / 48 B
  • OptimisticContentionBenchmarks.ParallelContentionFourWorkers: 2,629.2 ns / 976 B