Public .NET API ReferenceL2 Cross-Cutting & ReliabilityStableAOT: Full

EricksonLopez.Concurrency

Zero-allocation, Native AOT Optimistic Concurrency Control (OCC) and conflict resolution framework for .NET. Eliminates lost updates and race conditions across Dapper, ASP.NET Core, and relational databases.

27 namespaces82 types459 membersGenerated from XML docs & assemblies · UTC 2026-12-01

Showing 82 of 82 types (459 members)

EricksonLopez.Concurrency.Abstractions#

25
record

ActualVersion

Assembly: EricksonLopez.Concurrency.Abstractions
public readonly record struct ActualVersion : IComparable<ActualVersion>, IComparable
Implements: IComparable, IComparable<ActualVersion>

Represents the actual version discovered during persistence or conflict inspection.

Members (16)

  • constructorActualVersion
    public ActualVersion(ConcurrencyVersion version, bool exists = true)

    Initializes a new instance of the `ActualVersion` struct.

    version: ConcurrencyVersion
    The actual numeric concurrency version discovered in storage or memory.
    exists: bool
    A value indicating whether the entity exists in storage.
  • constructorActualVersion
    public ActualVersion(long version, bool exists = true)

    Initializes a new instance of the `ActualVersion` struct from a raw numeric value.

    version: long
    The raw 64-bit integer version discovered in storage.
    exists: bool
    A value indicating whether the entity exists in storage.
  • methodCompareTo
    public int CompareTo(ActualVersion other)

    Inherits documentation from base type or interface.

    other: ActualVersion
  • methodCompareTo
    public int CompareTo(object? obj)

    Inherits documentation from base type or interface.

    obj: object?

    Exceptions: ArgumentException: `obj` is not an instance of `ActualVersion`

  • methodFrom
    public static ActualVersion From(ConcurrencyVersion version)

    Creates an actual version instance from the specified `ConcurrencyVersion`.

    version: ConcurrencyVersion
    The concurrency version discovered in storage.

    Returns: A new `ActualVersion` instance indicating that the entity exists.

  • methodFrom
    public static ActualVersion From(long version)

    Creates an actual version instance from the specified numeric version value.

    version: long
    The 64-bit integer representing the actual version value.

    Returns: A new `ActualVersion` instance indicating that the entity exists.

  • methodToString
    public override string ToString()

    Inherits documentation from base type or interface.

  • methodimplicit operator ActualVersion
    public static implicit operator ActualVersion(ConcurrencyVersion version)

    Converts a `ConcurrencyVersion` to an `ActualVersion`.

    version: ConcurrencyVersion
    The concurrency version to convert.

    Returns: A new `ActualVersion` instance wrapping the specified concurrency version.

  • methodimplicit operator ActualVersion
    public static implicit operator ActualVersion(long value)

    Converts a 64-bit integer value to an `ActualVersion`.

    value: long
    The raw version value to convert.

    Returns: A new `ActualVersion` instance wrapping the specified 64-bit integer version value.

  • methodoperator <
    public static bool operator <(ActualVersion left, ActualVersion right)

    Determines whether the left actual version is less than the right actual version.

    left: ActualVersion
    The left actual version to compare.
    right: ActualVersion
    The right actual version to compare.

    Returns: `true` if `left` is less than `right`; otherwise, `false`.

  • methodoperator <=
    public static bool operator <=(ActualVersion left, ActualVersion right)

    Determines whether the left actual version is less than or equal to the right actual version.

    left: ActualVersion
    The left actual version to compare.
    right: ActualVersion
    The right actual version to compare.

    Returns: `true` if `left` is less than or equal to `right`; otherwise, `false`.

  • methodoperator >
    public static bool operator >(ActualVersion left, ActualVersion right)

    Determines whether the left actual version is greater than the right actual version.

    left: ActualVersion
    The left actual version to compare.
    right: ActualVersion
    The right actual version to compare.

    Returns: `true` if `left` is greater than `right`; otherwise, `false`.

  • methodoperator >=
    public static bool operator >=(ActualVersion left, ActualVersion right)

    Determines whether the left actual version is greater than or equal to the right actual version.

    left: ActualVersion
    The left actual version to compare.
    right: ActualVersion
    The right actual version to compare.

    Returns: `true` if `left` is greater than or equal to `right`; otherwise, `false`.

  • propertyExists
    public bool Exists { get; }

    Gets a value indicating whether the entity exists in storage.

  • propertyVersion
    public ConcurrencyVersion Version { get; }

    Gets the actual concurrency version discovered.

  • fieldNotFound
    public static readonly ActualVersion NotFound

    Represents an actual version indicating that the target entity was not found or has been deleted.

class

CasResult

Assembly: EricksonLopez.Concurrency.Abstractions
public static class CasResult

Provides non-generic factory methods for constructing `CasResult<TEntity>` instances.

Members (2)

  • methodConflicted<TEntity>
    public static CasResult<TEntity> Conflicted<TEntity>(ConcurrencyConflict conflict) where TEntity : class

    Creates a conflicted Compare-And-Swap result encapsulating the conflict descriptor.

    conflict: ConcurrencyConflict
    The conflict descriptor detailing the cause of failure.

    Returns: A conflicted `CasResult<TEntity>` containing the conflict descriptor.

    Type parameters: TEntity: The type of the target entity or aggregate root.

  • methodSucceeded<TEntity>
    public static CasResult<TEntity> Succeeded<TEntity>(TEntity entity, ConcurrencyVersion newVersion) where TEntity : class

    Creates a successful Compare-And-Swap result with the mutated entity and its new concurrency version.

    entity: TEntity
    The mutated entity instance.
    newVersion: ConcurrencyVersion
    The new concurrency version assigned after mutation.

    Returns: A successful `CasResult<TEntity>` containing the mutated entity and its assigned version.

    Type parameters: TEntity: The type of the target entity or aggregate root.

record

CasResult<TEntity>

Assembly: EricksonLopez.Concurrency.Abstractions
public readonly record struct CasResult<TEntity> where TEntity : class

Represents the result of an atomic or optimistic Compare-And-Swap (CAS) state transition.

Remarks:

Indicates either success with a mutated entity and version, or conflict with a populated conflict descriptor. Type parameters: TEntity: The type of the target entity or aggregate root.

Members (7)

  • constructorCasResult
    public CasResult(TEntity? entity, ConcurrencyVersion? newVersion, ConcurrencyConflict? conflict)

    Initializes a new instance of the `CasResult<TEntity>` struct.

    entity: TEntity?
    The mutated entity instance when successful; otherwise, `null`.
    newVersion: ConcurrencyVersion?
    The new concurrency version when successful; otherwise, `null`.
    conflict: ConcurrencyConflict?
    The conflict descriptor when conflicted; otherwise, `null`.
  • propertyConflict
    public ConcurrencyConflict? Conflict { get; }

    Gets the conflict descriptor if the operation failed due to a state mismatch; otherwise, `null`.

  • propertyEntity
    public TEntity? Entity { get; }

    Gets the mutated entity instance if successful; otherwise, `null`.

  • propertyIsConflict
    public bool IsConflict { get; }

    Gets a value indicating whether a concurrency conflict prevented the state transition.

  • propertyIsInitialized
    public bool IsInitialized { get; }

    Gets a value indicating whether this result has been initialized with either a success or a conflict.

  • propertyIsSuccess
    public bool IsSuccess { get; }

    Gets a value indicating whether the Compare-And-Swap operation succeeded.

  • propertyNewVersion
    public ConcurrencyVersion? NewVersion { get; }

    Gets the resulting new concurrency version if successful; otherwise, `null`.

class

ConcurrencyConfigurationException

Assembly: EricksonLopez.Concurrency.Abstractions
public sealed class ConcurrencyConfigurationException : ConcurrencyException
Inherits: ConcurrencyException

Represents an exception thrown when concurrency options, policies, or resolvers are misconfigured.

Members (3)

  • constructorConcurrencyConfigurationException
    public ConcurrencyConfigurationException()

    Initializes a new instance of the `ConcurrencyConfigurationException` class with a default error message.

  • constructorConcurrencyConfigurationException
    public ConcurrencyConfigurationException(string message)

    Initializes a new instance of the `ConcurrencyConfigurationException` class with a specified message.

    message: string
    The message that describes the error.
  • constructorConcurrencyConfigurationException
    public ConcurrencyConfigurationException(string message, Exception innerException)

    Initializes a new instance of the `ConcurrencyConfigurationException` class with a specified message and inner exception.

    message: string
    The message that describes the error.
    innerException: Exception
    The exception that is the cause of the current exception.
record

ConcurrencyConflict

Assembly: EricksonLopez.Concurrency.Abstractions
public sealed record ConcurrencyConflict

Encapsulates rich, immutable diagnostic and domain details of a detected concurrency conflict.

Members (16)

  • constructorConcurrencyConflict
    public ConcurrencyConflict(string entityId, string entityType, ConcurrencyConflictType conflictType, ConcurrencyConflictClassification classification, string operation, string message, ExpectedVersion? expectedVersion = null, ActualVersion? actualVersion = null, IConcurrencyToken? expectedToken = null, IConcurrencyToken? actualToken = null, DateTimeOffset? timestamp = null, IReadOnlyDictionary<string, string>? metadata = null)

    Initializes a new instance of the `ConcurrencyConflict` record.

    entityId: string
    The unique identifier of the entity involved in the conflict.
    entityType: string
    The type name or discriminator of the entity.
    conflictType: ConcurrencyConflictType
    The specific category of concurrency conflict.
    classification: ConcurrencyConflictClassification
    The operational classification of the conflict.
    operation: string
    The operation during which the conflict occurred.
    message: string
    The descriptive explanation of the conflict.
    expectedVersion: ExpectedVersion?
    The expected version constraint, if applicable.
    actualVersion: ActualVersion?
    The actual version discovered, if known.
    expectedToken: IConcurrencyToken?
    The expected concurrency token, if applicable.
    actualToken: IConcurrencyToken?
    The actual concurrency token discovered, if known.
    timestamp: DateTimeOffset?
    The UTC date and time when the conflict occurred, or `null` to use the current time.
    metadata: IReadOnlyDictionary<string, string>?
    Additional key-value pairs providing context for the conflict.
  • methodDeleted
    public static ConcurrencyConflict Deleted(string entityId, string entityType, string operation = "")

    Creates a `ConcurrencyConflict` indicating that the target entity was deleted or missing.

    entityId: string
    The identifier of the entity involved in the conflict.
    entityType: string
    The type name of the entity involved in the conflict.
    operation: string
    The operation name during which the conflict occurred.

    Returns: A new `ConcurrencyConflict` indicating that the entity does not exist.

  • methodTokenMismatch
    public static ConcurrencyConflict TokenMismatch(string entityId, string entityType, IConcurrencyToken expected, IConcurrencyToken? actual = null, string operation = "", IReadOnlyDictionary<string, string>? metadata = null)

    Creates a `ConcurrencyConflict` representing an opaque token mismatch.

    entityId: string
    The identifier of the entity involved in the conflict.
    entityType: string
    The type name of the entity involved in the conflict.
    expected: IConcurrencyToken
    The expected token constraint.
    actual: IConcurrencyToken?
    The actual token found in storage, if known.
    operation: string
    The operation name during which the conflict occurred.
    metadata: IReadOnlyDictionary<string, string>?
    Additional contextual metadata.

    Returns: A new `ConcurrencyConflict` configured for a token mismatch.

  • methodVersionMismatch
    public static ConcurrencyConflict VersionMismatch(string entityId, string entityType, ExpectedVersion expected, ActualVersion? actual = null, string operation = "", IReadOnlyDictionary<string, string>? metadata = null)

    Creates a `ConcurrencyConflict` representing a numeric version mismatch.

    entityId: string
    The identifier of the entity involved in the conflict.
    entityType: string
    The type name of the entity involved in the conflict.
    expected: ExpectedVersion
    The expected version constraint.
    actual: ActualVersion?
    The actual version discovered in storage, if known.
    operation: string
    The operation name during which the conflict occurred.
    metadata: IReadOnlyDictionary<string, string>?
    Additional contextual metadata.

    Returns: A new `ConcurrencyConflict` configured for a version mismatch.

  • propertyActualToken
    public IConcurrencyToken? ActualToken { get; init; }

    Gets the actual concurrency token discovered in storage, or `null` if not known.

  • propertyActualVersion
    public ActualVersion? ActualVersion { get; init; }

    Gets the actual version discovered in persistence or memory, or `null` if not known.

  • propertyClassification
    public ConcurrencyConflictClassification Classification { get; init; }

    Gets the high-level operational classification of the conflict (e.g., Transient, StaleState, NonRetryable).

  • propertyConflictType
    public ConcurrencyConflictType ConflictType { get; init; }

    Gets the specific category of concurrency conflict.

  • propertyEntityId
    public string EntityId { get; init; }

    Gets the unique identifier of the entity or aggregate involved in the conflict.

  • propertyEntityType
    public string EntityType { get; init; }

    Gets the type name or discriminator of the entity or aggregate involved in the conflict.

  • propertyExpectedToken
    public IConcurrencyToken? ExpectedToken { get; init; }

    Gets the expected concurrency token specified by the caller, or `null` if not token-based.

  • propertyExpectedVersion
    public ExpectedVersion? ExpectedVersion { get; init; }

    Gets the expected version specified by the caller, or `null` if not version-based.

  • propertyMessage
    public string Message { get; init; }

    Gets the diagnostic message describing the conflict.

  • propertyMetadata
    public IReadOnlyDictionary<string, string> Metadata { get; init; }

    Gets contextual metadata associated with the conflict.

  • propertyOperation
    public string Operation { get; init; }

    Gets the name of the operation during which the conflict occurred.

  • propertyTimestamp
    public DateTimeOffset Timestamp { get; init; }

    Gets the UTC date and time when the conflict was detected.

enum

ConcurrencyConflictClassification

Assembly: EricksonLopez.Concurrency.Abstractions
public enum ConcurrencyConflictClassification : byte

Classifies a concurrency conflict to guide higher-level resilience, retry, and operational decisions.

Members (5)

  • fieldFatal
    Fatal = 4

    Fatal or corrupted concurrency condition.

  • fieldNonRetryable
    NonRetryable = 2

    Non-retryable state conflict that requires client interaction or manual resolution.

  • fieldRetryable
    Retryable = 1

    Conflict that is safe to retry by reloading state and reapplying domain invariants.

  • fieldStaleState
    StaleState = 3

    Stale client state where the resource has significantly progressed.

  • fieldTransient
    Transient = 0

    Transient database conflict (e.g. deadlock, serialization failure) that may succeed upon immediate transaction retry.

enum

ConcurrencyConflictType

Assembly: EricksonLopez.Concurrency.Abstractions
public enum ConcurrencyConflictType : byte

Specifies the nature and category of a detected concurrency conflict.

Members (8)

  • fieldAlreadyExists
    AlreadyExists = 3

    Indicates that the target entity already exists when expected to be new.

  • fieldCustom
    Custom = 7

    Custom or user-defined conflict condition.

  • fieldDeadlock
    Deadlock = 5

    Indicates that a database deadlock was detected between concurrent operations (e.g. PostgreSQL SQLSTATE 40P01).

  • fieldLockUnavailable
    LockUnavailable = 6

    Indicates that a lock acquisition timed out or was unavailable (e.g. PostgreSQL NOWAIT / 55P03).

  • fieldSerializationFailure
    SerializationFailure = 4

    Indicates that a database transaction serialization failure occurred (e.g. PostgreSQL SQLSTATE 40001).

  • fieldStateDeleted
    StateDeleted = 2

    Indicates that the target entity was deleted or not found during update execution.

  • fieldTokenMismatch
    TokenMismatch = 1

    Indicates that the concurrency token does not match the expected token.

  • fieldVersionMismatch
    VersionMismatch = 0

    Indicates that the entity version does not match the expected version.

class

ConcurrencyException

Assembly: EricksonLopez.Concurrency.Abstractions
public class ConcurrencyException : Exception
Inherits: Exception

Represents the base exception thrown when an unhandled concurrency conflict occurs in an exceptional flow.

Remarks:

Under normal operation, concurrency conflicts should be represented via monadic results rather than exceptions. This exception is reserved for scenarios where exceptional throw semantics are strictly required.

Members (5)

  • constructorConcurrencyException
    public ConcurrencyException()

    Initializes a new instance of the `ConcurrencyException` class with a default error message.

  • constructorConcurrencyException
    public ConcurrencyException(ConcurrencyConflict conflict)

    Initializes a new instance of the `ConcurrencyException` class with a specified conflict descriptor.

    conflict: ConcurrencyConflict
    The conflict descriptor containing detailed diagnostics.
  • constructorConcurrencyException
    public ConcurrencyException(string message)

    Initializes a new instance of the `ConcurrencyException` class with a specified message.

    message: string
    The message that describes the error.
  • constructorConcurrencyException
    public ConcurrencyException(string message, Exception innerException)

    Initializes a new instance of the `ConcurrencyException` class with a specified message and inner exception.

    message: string
    The message that describes the error.
    innerException: Exception
    The exception that is the cause of the current exception.
  • propertyConflict
    public ConcurrencyConflict? Conflict { get; }

    Gets the conflict descriptor associated with this exception, if available.

record

ConcurrencyToken

Assembly: EricksonLopez.Concurrency.Abstractions
public readonly record struct ConcurrencyToken : IConcurrencyToken, IComparable<ConcurrencyToken>, IComparable
Implements: IComparable, IComparable<ConcurrencyToken>, IConcurrencyToken

Represents an immutable, opaque concurrency token used to validate state consistency.

Members (19)

  • constructorConcurrencyToken
    public ConcurrencyToken(string value, string tokenKind = "")

    Initializes a new instance of the `ConcurrencyToken` struct with a specific value and kind.

    value: string
    The string value of the token.
    tokenKind: string
    The descriptive kind of the token.
  • methodCompareTo
    public int CompareTo(ConcurrencyToken other)

    Inherits documentation from base type or interface.

    other: ConcurrencyToken
  • methodCompareTo
    public int CompareTo(object? obj)

    Inherits documentation from base type or interface.

    obj: object?

    Exceptions: ArgumentException: `obj` is not an instance of `ConcurrencyToken`

  • methodEquals
    public bool Equals(ConcurrencyToken other)

    Indicates whether the current concurrency token is equal to another token of the same type.

    other: ConcurrencyToken
    An object to compare with this token.

    Returns: `true` if the current token is equal to the `other` parameter; otherwise, `false`.

  • methodEquals
    public bool Equals(IConcurrencyToken? other)

    Inherits documentation from base type or interface.

    other: IConcurrencyToken?
  • methodFrom
    public static ConcurrencyToken From(Guid tokenValue)

    Creates a new concurrency token from a `Guid`.

    tokenValue: Guid
    The unique identifier value.

    Returns: A new `ConcurrencyToken` formatted as a 32-character hexadecimal string without hyphens.

  • methodFrom
    public static ConcurrencyToken From(string value, string kind = "")

    Creates a new concurrency token from a string.

    value: string
    The string token value.
    kind: string
    The token kind discriminator.

    Returns: A new `ConcurrencyToken` containing the specified string value and kind.

  • methodFrom
    public static ConcurrencyToken From(byte[] bytes)

    Creates a new concurrency token from a byte array.

    bytes: byte[]
    The byte array containing binary concurrency data (e.g., SQL rowversion).

    Returns: A new `ConcurrencyToken` with hex-encoded string representation and kind "RowVersion".

    Exceptions: ArgumentNullException: `bytes` is `null`

  • methodGetHashCode
    public override int GetHashCode()

    Inherits documentation from base type or interface.

  • methodNewGuid
    public static ConcurrencyToken NewGuid()

    Generates a new cryptographically unique GUID-based concurrency token.

    Returns: A new unique `ConcurrencyToken`.

  • methodToString
    public override string ToString()

    Inherits documentation from base type or interface.

  • methodoperator <
    public static bool operator <(ConcurrencyToken left, ConcurrencyToken right)

    Determines whether the left token is less than the right token.

    left: ConcurrencyToken
    The left token to compare.
    right: ConcurrencyToken
    The right token to compare.

    Returns: `true` if `left` is less than `right`; otherwise, `false`.

  • methodoperator <=
    public static bool operator <=(ConcurrencyToken left, ConcurrencyToken right)

    Determines whether the left token is less than or equal to the right token.

    left: ConcurrencyToken
    The left token to compare.
    right: ConcurrencyToken
    The right token to compare.

    Returns: `true` if `left` is less than or equal to `right`; otherwise, `false`.

  • methodoperator >
    public static bool operator >(ConcurrencyToken left, ConcurrencyToken right)

    Determines whether the left token is greater than the right token.

    left: ConcurrencyToken
    The left token to compare.
    right: ConcurrencyToken
    The right token to compare.

    Returns: `true` if `left` is greater than `right`; otherwise, `false`.

  • methodoperator >=
    public static bool operator >=(ConcurrencyToken left, ConcurrencyToken right)

    Determines whether the left token is greater than or equal to the right token.

    left: ConcurrencyToken
    The left token to compare.
    right: ConcurrencyToken
    The right token to compare.

    Returns: `true` if `left` is greater than or equal to `right`; otherwise, `false`.

  • propertyIsEmpty
    public bool IsEmpty { get; }

    Gets a value indicating whether the token represents an empty or uninitialized state.

  • propertyTokenKind
    public string TokenKind { get; }

    Gets the discriminator or kind of token (e.g. "String", "Guid", "RowVersion", "Hash").

  • propertyValue
    public string Value { get; }

    Gets the raw string value of the token.

  • fieldNone
    public static readonly ConcurrencyToken None

    Represents an empty, uninitialized concurrency token.

class

ConcurrencyTokenMismatchException

Assembly: EricksonLopez.Concurrency.Abstractions
public sealed class ConcurrencyTokenMismatchException : ConcurrencyException
Inherits: ConcurrencyException

Represents an exception thrown when a strict concurrency token comparison fails.

Members (6)

  • constructorConcurrencyTokenMismatchException
    public ConcurrencyTokenMismatchException()

    Initializes a new instance of the `ConcurrencyTokenMismatchException` class with a default error message.

  • constructorConcurrencyTokenMismatchException
    public ConcurrencyTokenMismatchException(IConcurrencyToken expectedToken, IConcurrencyToken actualToken)

    Initializes a new instance of the `ConcurrencyTokenMismatchException` class with the expected and actual tokens.

    expectedToken: IConcurrencyToken
    The expected concurrency token constraint.
    actualToken: IConcurrencyToken
    The actual concurrency token found in storage.
  • constructorConcurrencyTokenMismatchException
    public ConcurrencyTokenMismatchException(string message)

    Initializes a new instance of the `ConcurrencyTokenMismatchException` class with a specified message.

    message: string
    The message describing the error.
  • constructorConcurrencyTokenMismatchException
    public ConcurrencyTokenMismatchException(string message, Exception innerException)

    Initializes a new instance of the `ConcurrencyTokenMismatchException` class with a specified message and inner exception.

    message: string
    The message describing the error.
    innerException: Exception
    The exception that is the cause of the current exception.
  • propertyActualToken
    public IConcurrencyToken? ActualToken { get; }

    Gets the actual concurrency token found in storage.

  • propertyExpectedToken
    public IConcurrencyToken? ExpectedToken { get; }

    Gets the expected concurrency token constraint.

record

ConcurrencyVersion

Assembly: EricksonLopez.Concurrency.Abstractions
public readonly record struct ConcurrencyVersion : IComparable<ConcurrencyVersion>, IComparable, ISpanFormattable, ISpanParsable<ConcurrencyVersion>, IParsable<ConcurrencyVersion>
Implements: IComparable, IComparable<ConcurrencyVersion>, IParsable<ConcurrencyVersion>, ISpanFormattable, ISpanParsable<ConcurrencyVersion>

Represents an immutable, zero-allocation strongly-typed numeric concurrency version.

Members (26)

  • constructorConcurrencyVersion
    public ConcurrencyVersion(long value)

    Initializes a new instance of the `ConcurrencyVersion` struct with the specified numeric value.

    value: long
    The non-negative numeric version value.

    Exceptions: ArgumentOutOfRangeException: `value` is negative

  • methodCompareTo
    public int CompareTo(ConcurrencyVersion other)

    Inherits documentation from base type or interface.

    other: ConcurrencyVersion
  • methodCompareTo
    public int CompareTo(object? obj)

    Inherits documentation from base type or interface.

    obj: object?

    Exceptions: ArgumentException: `obj` is not an instance of `ConcurrencyVersion`

  • methodFrom
    public static ConcurrencyVersion From(long value)

    Creates a new `ConcurrencyVersion` instance from the specified numeric value.

    value: long
    The 64-bit integer representing the version value.

    Returns: A new `ConcurrencyVersion` configured with the specified numeric value.

  • methodNext
    public ConcurrencyVersion Next()

    Returns the next sequential concurrency version.

    Returns: A new `ConcurrencyVersion` incremented by 1.

    Exceptions: OverflowException: The incremented version exceeds `long.MaxValue`

  • methodParse
    public static ConcurrencyVersion Parse(ReadOnlySpan<char> s)

    Parses a span of characters into a `ConcurrencyVersion` using invariant culture.

    s: ReadOnlySpan<char>
    The span of characters to parse.

    Returns: The parsed `ConcurrencyVersion`.

    Exceptions: FormatException: `s` is not in the correct format or represents a negative value

  • methodParse
    public static ConcurrencyVersion Parse(ReadOnlySpan<char> s, IFormatProvider? provider)

    Parses a span of characters into a `ConcurrencyVersion`.

    s: ReadOnlySpan<char>
    The span of characters to parse.
    provider: IFormatProvider?
    An object that provides culture-specific formatting information.

    Returns: The parsed `ConcurrencyVersion`.

    Exceptions: FormatException: `s` is not in the correct format or represents a negative value

  • methodParse
    public static ConcurrencyVersion Parse(string s)

    Parses a string into a `ConcurrencyVersion` using invariant culture.

    s: string
    The string to parse.

    Returns: The parsed `ConcurrencyVersion`.

    Exceptions: ArgumentNullException: `s` is `null`; FormatException: `s` is not in the correct format or represents a negative value

  • methodParse
    public static ConcurrencyVersion Parse(string s, IFormatProvider? provider)

    Parses a string into a `ConcurrencyVersion`.

    s: string
    The string to parse.
    provider: IFormatProvider?
    An object that provides culture-specific formatting information.

    Returns: The parsed `ConcurrencyVersion`.

    Exceptions: ArgumentNullException: `s` is `null`; FormatException: `s` is not in the correct format or represents a negative value

  • methodToString
    public override string ToString()

    Inherits documentation from base type or interface.

  • methodToString
    public string ToString(string? format, IFormatProvider? formatProvider)

    Inherits documentation from base type or interface.

    format: string?
    formatProvider: IFormatProvider?
  • methodTryFormat
    public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)

    Inherits documentation from base type or interface.

    destination: Span<char>
    charsWritten: out int
    format: ReadOnlySpan<char>
    provider: IFormatProvider?
  • methodTryParse
    public static bool TryParse(ReadOnlySpan<char> s, out ConcurrencyVersion result)

    Attempts to parse a span of characters into a `ConcurrencyVersion` using invariant culture.

    s: ReadOnlySpan<char>
    The span of characters to parse.
    result: out ConcurrencyVersion
    When this method returns, contains the parsed `ConcurrencyVersion` if successful; otherwise, `None`.

    Returns: `true` if parsing succeeded; otherwise, `false`.

  • methodTryParse
    public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out ConcurrencyVersion result)

    Attempts to parse a span of characters into a `ConcurrencyVersion`.

    s: ReadOnlySpan<char>
    The span of characters to parse.
    provider: IFormatProvider?
    An object that provides culture-specific formatting information.
    result: out ConcurrencyVersion
    When this method returns, contains the parsed `ConcurrencyVersion` if successful; otherwise, `None`.

    Returns: `true` if parsing succeeded; otherwise, `false`.

  • methodTryParse
    public static bool TryParse(string? s, out ConcurrencyVersion result)

    Attempts to parse a string into a `ConcurrencyVersion` using invariant culture.

    s: string?
    The string to parse.
    result: out ConcurrencyVersion
    When this method returns, contains the parsed `ConcurrencyVersion` if successful; otherwise, `None`.

    Returns: `true` if parsing succeeded; otherwise, `false`.

  • methodTryParse
    public static bool TryParse(string? s, IFormatProvider? provider, out ConcurrencyVersion result)

    Attempts to parse a string into a `ConcurrencyVersion`.

    s: string?
    The string to parse.
    provider: IFormatProvider?
    An object that provides culture-specific formatting information.
    result: out ConcurrencyVersion
    When this method returns, contains the parsed `ConcurrencyVersion` if successful; otherwise, `None`.

    Returns: `true` if parsing succeeded; otherwise, `false`.

  • methodexplicit operator ConcurrencyVersion
    public static explicit operator ConcurrencyVersion(long value)

    Converts a 64-bit signed integer to a `ConcurrencyVersion`.

    value: long
    The 64-bit integer version value to convert.

    Returns: A new `ConcurrencyVersion` instance with the specified numeric value.

    Exceptions: ArgumentOutOfRangeException: `value` is negative

  • methodimplicit operator long
    public static implicit operator long(ConcurrencyVersion version)

    Converts a `ConcurrencyVersion` to a 64-bit signed integer.

    version: ConcurrencyVersion
    The concurrency version instance to convert.

    Returns: The underlying 64-bit signed integer version value.

  • methodoperator <
    public static bool operator <(ConcurrencyVersion left, ConcurrencyVersion right)

    Determines whether the left version is less than the right version.

    left: ConcurrencyVersion
    The left version to compare.
    right: ConcurrencyVersion
    The right version to compare.

    Returns: `true` if `left` is less than `right`; otherwise, `false`.

  • methodoperator <=
    public static bool operator <=(ConcurrencyVersion left, ConcurrencyVersion right)

    Determines whether the left version is less than or equal to the right version.

    left: ConcurrencyVersion
    The left version to compare.
    right: ConcurrencyVersion
    The right version to compare.

    Returns: `true` if `left` is less than or equal to `right`; otherwise, `false`.

  • methodoperator >
    public static bool operator >(ConcurrencyVersion left, ConcurrencyVersion right)

    Determines whether the left version is greater than the right version.

    left: ConcurrencyVersion
    The left version to compare.
    right: ConcurrencyVersion
    The right version to compare.

    Returns: `true` if `left` is greater than `right`; otherwise, `false`.

  • methodoperator >=
    public static bool operator >=(ConcurrencyVersion left, ConcurrencyVersion right)

    Determines whether the left version is greater than or equal to the right version.

    left: ConcurrencyVersion
    The left version to compare.
    right: ConcurrencyVersion
    The right version to compare.

    Returns: `true` if `left` is greater than or equal to `right`; otherwise, `false`.

  • propertyIsNone
    public bool IsNone { get; }

    Gets a value indicating whether this version represents an uninitialized or empty version.

  • propertyValue
    public long Value { get; }

    Gets the underlying 64-bit integer version value.

  • fieldInitial
    public static readonly ConcurrencyVersion Initial

    Represents the initial concurrency version for newly created entities (1).

  • fieldNone
    public static readonly ConcurrencyVersion None

    Represents the uninitialized or non-existent concurrency version (0).

record

ConcurrencyVersion<TEntity>

Assembly: EricksonLopez.Concurrency.Abstractions
public readonly record struct ConcurrencyVersion<TEntity> : IComparable<ConcurrencyVersion<TEntity>>, IComparable, ISpanFormattable, ISpanParsable<ConcurrencyVersion<TEntity>>, IParsable<ConcurrencyVersion<TEntity>> where TEntity : class
Implements: IComparable, IComparable<ConcurrencyVersion<TEntity>>, IParsable<ConcurrencyVersion<TEntity>>, ISpanFormattable, ISpanParsable<ConcurrencyVersion<TEntity>>

Represents an immutable, strongly-typed numeric concurrency version bound to a specific entity or aggregate type `TEntity`.

Remarks:

Type parameters: TEntity: The type of the domain entity or aggregate root.

Members (27)

  • constructorConcurrencyVersion
    public ConcurrencyVersion(ConcurrencyVersion version)

    Initializes a new instance of the `ConcurrencyVersion<TEntity>` struct from an untyped `ConcurrencyVersion`.

    version: ConcurrencyVersion
    The untyped concurrency version.
  • constructorConcurrencyVersion
    public ConcurrencyVersion(long value)

    Initializes a new instance of the `ConcurrencyVersion<TEntity>` struct with the specified numeric value.

    value: long
    The non-negative numeric version value.

    Exceptions: ArgumentOutOfRangeException: `value` is negative

  • methodCompareTo
    public int CompareTo(ConcurrencyVersion<TEntity> other)

    Inherits documentation from base type or interface.

    other: ConcurrencyVersion<TEntity>
  • methodCompareTo
    public int CompareTo(object? obj)

    Inherits documentation from base type or interface.

    obj: object?

    Exceptions: ArgumentException: `obj` is not an instance of `ConcurrencyVersion<TEntity>`

  • methodNext
    public ConcurrencyVersion<TEntity> Next()

    Returns the next sequential concurrency version.

    Returns: A new `ConcurrencyVersion<TEntity>` incremented by 1.

    Exceptions: OverflowException: The incremented version exceeds `long.MaxValue`

  • methodParse
    public static ConcurrencyVersion<TEntity> Parse(ReadOnlySpan<char> s)

    Parses a span of characters into a `ConcurrencyVersion<TEntity>` using invariant culture.

    s: ReadOnlySpan<char>
    The span of characters to parse.

    Returns: The parsed `ConcurrencyVersion<TEntity>`.

    Exceptions: FormatException: `s` is not in the correct format or represents a negative value

  • methodParse
    public static ConcurrencyVersion<TEntity> Parse(ReadOnlySpan<char> s, IFormatProvider? provider)

    Parses a span of characters into a `ConcurrencyVersion<TEntity>`.

    s: ReadOnlySpan<char>
    The span of characters to parse.
    provider: IFormatProvider?
    An object that provides culture-specific formatting information.

    Returns: The parsed `ConcurrencyVersion<TEntity>`.

    Exceptions: FormatException: `s` is not in the correct format or represents a negative value

  • methodParse
    public static ConcurrencyVersion<TEntity> Parse(string s)

    Parses a string into a `ConcurrencyVersion<TEntity>` using invariant culture.

    s: string
    The string to parse.

    Returns: The parsed `ConcurrencyVersion<TEntity>`.

    Exceptions: ArgumentNullException: `s` is `null`; FormatException: `s` is not in the correct format or represents a negative value

  • methodParse
    public static ConcurrencyVersion<TEntity> Parse(string s, IFormatProvider? provider)

    Parses a string into a `ConcurrencyVersion<TEntity>`.

    s: string
    The string to parse.
    provider: IFormatProvider?
    An object that provides culture-specific formatting information.

    Returns: The parsed `ConcurrencyVersion<TEntity>`.

    Exceptions: ArgumentNullException: `s` is `null`; FormatException: `s` is not in the correct format or represents a negative value

  • methodToString
    public override string ToString()

    Inherits documentation from base type or interface.

  • methodToString
    public string ToString(string? format, IFormatProvider? formatProvider)

    Inherits documentation from base type or interface.

    format: string?
    formatProvider: IFormatProvider?
  • methodToUntyped
    public ConcurrencyVersion ToUntyped()

    Converts this typed version to an untyped `ConcurrencyVersion`.

    Returns: An untyped `ConcurrencyVersion` with the same numeric value.

  • methodTryFormat
    public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)

    Inherits documentation from base type or interface.

    destination: Span<char>
    charsWritten: out int
    format: ReadOnlySpan<char>
    provider: IFormatProvider?
  • methodTryParse
    public static bool TryParse(ReadOnlySpan<char> s, out ConcurrencyVersion<TEntity> result)

    Attempts to parse a span of characters into a `ConcurrencyVersion<TEntity>` using invariant culture.

    s: ReadOnlySpan<char>
    The span of characters to parse.
    result: out ConcurrencyVersion<TEntity>
    When this method returns, contains the parsed `ConcurrencyVersion<TEntity>` if successful; otherwise, `None`.

    Returns: `true` if parsing succeeded; otherwise, `false`.

  • methodTryParse
    public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out ConcurrencyVersion<TEntity> result)

    Attempts to parse a span of characters into a `ConcurrencyVersion<TEntity>`.

    s: ReadOnlySpan<char>
    The span of characters to parse.
    provider: IFormatProvider?
    An object that provides culture-specific formatting information.
    result: out ConcurrencyVersion<TEntity>
    When this method returns, contains the parsed `ConcurrencyVersion<TEntity>` if successful; otherwise, `None`.

    Returns: `true` if parsing succeeded; otherwise, `false`.

  • methodTryParse
    public static bool TryParse(string? s, out ConcurrencyVersion<TEntity> result)

    Attempts to parse a string into a `ConcurrencyVersion<TEntity>` using invariant culture.

    s: string?
    The string to parse.
    result: out ConcurrencyVersion<TEntity>
    When this method returns, contains the parsed `ConcurrencyVersion<TEntity>` if successful; otherwise, `None`.

    Returns: `true` if parsing succeeded; otherwise, `false`.

  • methodTryParse
    public static bool TryParse(string? s, IFormatProvider? provider, out ConcurrencyVersion<TEntity> result)

    Attempts to parse a string into a `ConcurrencyVersion<TEntity>`.

    s: string?
    The string to parse.
    provider: IFormatProvider?
    An object that provides culture-specific formatting information.
    result: out ConcurrencyVersion<TEntity>
    When this method returns, contains the parsed `ConcurrencyVersion<TEntity>` if successful; otherwise, `None`.

    Returns: `true` if parsing succeeded; otherwise, `false`.

  • methodexplicit operator ConcurrencyVersion<TEntity>
    public static explicit operator ConcurrencyVersion<TEntity>(long value)

    Converts a 64-bit signed integer to a `ConcurrencyVersion<TEntity>`.

    value: long
    The raw version value to convert.

    Returns: A new `ConcurrencyVersion<TEntity>` instance with the specified numeric value.

    Exceptions: ArgumentOutOfRangeException: `value` is negative

  • methodimplicit operator long
    public static implicit operator long(ConcurrencyVersion<TEntity> version)

    Converts a `ConcurrencyVersion<TEntity>` to a 64-bit signed integer.

    version: ConcurrencyVersion<TEntity>
    The typed version instance to convert.

    Returns: The underlying 64-bit signed integer version value.

  • methodoperator <
    public static bool operator <(ConcurrencyVersion<TEntity> left, ConcurrencyVersion<TEntity> right)

    Determines whether the left version is less than the right version.

    left: ConcurrencyVersion<TEntity>
    The left typed version to compare.
    right: ConcurrencyVersion<TEntity>
    The right typed version to compare.

    Returns: `true` if `left` is less than `right`; otherwise, `false`.

  • methodoperator <=
    public static bool operator <=(ConcurrencyVersion<TEntity> left, ConcurrencyVersion<TEntity> right)

    Determines whether the left version is less than or equal to the right version.

    left: ConcurrencyVersion<TEntity>
    The left typed version to compare.
    right: ConcurrencyVersion<TEntity>
    The right typed version to compare.

    Returns: `true` if `left` is less than or equal to `right`; otherwise, `false`.

  • methodoperator >
    public static bool operator >(ConcurrencyVersion<TEntity> left, ConcurrencyVersion<TEntity> right)

    Determines whether the left version is greater than the right version.

    left: ConcurrencyVersion<TEntity>
    The left typed version to compare.
    right: ConcurrencyVersion<TEntity>
    The right typed version to compare.

    Returns: `true` if `left` is greater than `right`; otherwise, `false`.

  • methodoperator >=
    public static bool operator >=(ConcurrencyVersion<TEntity> left, ConcurrencyVersion<TEntity> right)

    Determines whether the left version is greater than or equal to the right version.

    left: ConcurrencyVersion<TEntity>
    The left typed version to compare.
    right: ConcurrencyVersion<TEntity>
    The right typed version to compare.

    Returns: `true` if `left` is greater than or equal to `right`; otherwise, `false`.

  • propertyIsNone
    public bool IsNone { get; }

    Gets a value indicating whether this version represents an uninitialized or empty version.

  • propertyValue
    public long Value { get; }

    Gets the underlying 64-bit integer version value.

  • fieldInitial
    public static readonly ConcurrencyVersion<TEntity> Initial

    Represents the initial concurrency version for newly created entities of type `TEntity` (1).

  • fieldNone
    public static readonly ConcurrencyVersion<TEntity> None

    Represents the uninitialized or non-existent concurrency version (0) for `TEntity`.

class

ConflictResolution

Assembly: EricksonLopez.Concurrency.Abstractions
public static class ConflictResolution

Provides non-generic helper factory methods for creating `ConflictResolution<TEntity>` instances.

Members (4)

  • methodLastWriteWins<TEntity>
    public static ConflictResolution<TEntity> LastWriteWins<TEntity>(TEntity entity, string? reason = null) where TEntity : class

    Creates a resolution explicitly applying a Last-Write-Wins overwrite strategy.

    entity: TEntity
    The entity state to overwrite storage with.
    reason: string?
    An optional explanation detailing the Last-Write-Wins justification.

    Returns: An overwrite `ConflictResolution<TEntity>` instance.

    Type parameters: TEntity: The type of the domain entity or aggregate root.

  • methodMerged<TEntity>
    public static ConflictResolution<TEntity> Merged<TEntity>(TEntity mergedEntity, string? reason = null) where TEntity : class

    Creates a resolution utilizing a domain-merged entity state.

    mergedEntity: TEntity
    The reconciled entity state adhering to business invariants.
    reason: string?
    An optional explanation describing the domain merge resolution.

    Returns: A merged `ConflictResolution<TEntity>` instance.

    Type parameters: TEntity: The type of the domain entity or aggregate root.

  • methodRefreshedAndRetried<TEntity>
    public static ConflictResolution<TEntity> RefreshedAndRetried<TEntity>(TEntity refreshedEntity, string? reason = null) where TEntity : class

    Creates a resolution indicating that the entity was refreshed from persistent storage and re-evaluated.

    refreshedEntity: TEntity
    The refreshed and updated entity state.
    reason: string?
    An optional explanation describing the refresh and retry outcome.

    Returns: A refreshed `ConflictResolution<TEntity>` instance.

    Type parameters: TEntity: The type of the domain entity or aggregate root.

  • methodRejected<TEntity>
    public static ConflictResolution<TEntity> Rejected<TEntity>(string? reason = null) where TEntity : class

    Creates a resolution indicating that the conflict was rejected and should result in an unhandled failure.

    reason: string?
    An optional explanation for rejecting the conflict.

    Returns: A rejected `ConflictResolution<TEntity>` instance.

    Type parameters: TEntity: The type of the domain entity or aggregate root.

enum

ConflictResolutionStrategy

Assembly: EricksonLopez.Concurrency.Abstractions
public enum ConflictResolutionStrategy : byte

Defines the strategy used to resolve a detected optimistic concurrency conflict.

Members (4)

  • fieldLastWriteWinsExplicit
    LastWriteWinsExplicit = 1

    Explicitly overwrite storage with the latest in-memory state (explicit Last-Write-Wins; not recommended by default).

  • fieldMergeDomainSpecific
    MergeDomainSpecific = 2

    Execute a domain-specific merge reconciling both states without losing business invariant consistency.

  • fieldRefreshAndRetry
    RefreshAndRetry = 3

    Reload the latest state from storage, re-apply the domain mutation, and retry.

  • fieldReject
    Reject = 0

    Reject the update and return a conflict failure to the caller (default).

record

ConflictResolution<TEntity>

Assembly: EricksonLopez.Concurrency.Abstractions
public readonly record struct ConflictResolution<TEntity> where TEntity : class

Represents the outcome of a domain or infrastructure conflict resolution evaluation.

Remarks:

Type parameters: TEntity: The type of the domain entity or aggregate root.

Members (5)

  • constructorConflictResolution
    public ConflictResolution(TEntity? resolvedEntity, ConflictResolutionStrategy strategy, string? reason)

    Initializes a new instance of the `ConflictResolution<TEntity>` struct.

    resolvedEntity: TEntity?
    The resolved entity instance when resolved; otherwise, `null`.
    strategy: ConflictResolutionStrategy
    The conflict resolution strategy applied.
    reason: string?
    An optional explanation describing the resolution.
  • propertyIsResolved
    public bool IsResolved { get; }

    Gets a value indicating whether the conflict was successfully resolved with a valid entity state.

  • propertyReason
    public string? Reason { get; }

    Gets an optional explanation for the chosen conflict resolution.

  • propertyResolvedEntity
    public TEntity? ResolvedEntity { get; }

    Gets the resolved entity state, or `null` if the conflict was rejected.

  • propertyStrategy
    public ConflictResolutionStrategy Strategy { get; }

    Gets the conflict resolution strategy applied.

record

ExpectedVersion

Assembly: EricksonLopez.Concurrency.Abstractions
public readonly record struct ExpectedVersion : IComparable<ExpectedVersion>, IComparable
Implements: IComparable, IComparable<ExpectedVersion>

Represents an optimistic expectation of an entity's version before applying modifications.

Remarks:

Important: The default value `default(ExpectedVersion)` evaluates to `ExpectedVersionKind.Specific` with a version of `0`. It does not mean "Any" version. To disable version checks, explicitly use `Any`.

Members (17)

  • methodCompareTo
    public int CompareTo(ExpectedVersion other)

    Inherits documentation from base type or interface.

    other: ExpectedVersion
  • methodCompareTo
    public int CompareTo(object? obj)

    Inherits documentation from base type or interface.

    obj: object?

    Exceptions: ArgumentException: `obj` is not an instance of `ExpectedVersion`

  • methodMatches
    public bool Matches(ConcurrencyVersion actual)

    Determines whether the specified actual version satisfies this expected version contract.

    actual: ConcurrencyVersion
    The actual concurrency version found in storage or memory.

    Returns: `true` if the actual version matches the expectation; otherwise, `false`.

  • methodSpecific
    public static ExpectedVersion Specific(ConcurrencyVersion version)

    Creates an `ExpectedVersion` representing an exact `ConcurrencyVersion`.

    version: ConcurrencyVersion
    The exact expected concurrency version.

    Returns: A new `ExpectedVersion` configured with `ExpectedVersionKind.Specific`.

  • methodSpecific
    public static ExpectedVersion Specific(long version)

    Creates an `ExpectedVersion` representing an exact numeric version value.

    version: long
    The exact expected 64-bit integer version value.

    Returns: A new `ExpectedVersion` configured with `ExpectedVersionKind.Specific`.

  • methodToString
    public override string ToString()

    Inherits documentation from base type or interface.

  • methodimplicit operator ExpectedVersion
    public static implicit operator ExpectedVersion(ConcurrencyVersion version)

    Converts a `ConcurrencyVersion` to a specific `ExpectedVersion`.

    version: ConcurrencyVersion
    The specific concurrency version to convert.

    Returns: A new `ExpectedVersion` configured with `ExpectedVersionKind.Specific`.

  • methodimplicit operator ExpectedVersion
    public static implicit operator ExpectedVersion(long value)

    Converts a 64-bit integer value to a specific `ExpectedVersion`.

    value: long
    The specific 64-bit integer version value to convert.

    Returns: A new `ExpectedVersion` configured with `ExpectedVersionKind.Specific`.

  • methodoperator <
    public static bool operator <(ExpectedVersion left, ExpectedVersion right)

    Determines whether the left expected version is less than the right expected version.

    left: ExpectedVersion
    The left expected version to compare.
    right: ExpectedVersion
    The right expected version to compare.

    Returns: `true` if `left` is less than `right`; otherwise, `false`.

  • methodoperator <=
    public static bool operator <=(ExpectedVersion left, ExpectedVersion right)

    Determines whether the left expected version is less than or equal to the right expected version.

    left: ExpectedVersion
    The left expected version to compare.
    right: ExpectedVersion
    The right expected version to compare.

    Returns: `true` if `left` is less than or equal to `right`; otherwise, `false`.

  • methodoperator >
    public static bool operator >(ExpectedVersion left, ExpectedVersion right)

    Determines whether the left expected version is greater than the right expected version.

    left: ExpectedVersion
    The left expected version to compare.
    right: ExpectedVersion
    The right expected version to compare.

    Returns: `true` if `left` is greater than `right`; otherwise, `false`.

  • methodoperator >=
    public static bool operator >=(ExpectedVersion left, ExpectedVersion right)

    Determines whether the left expected version is greater than or equal to the right expected version.

    left: ExpectedVersion
    The left expected version to compare.
    right: ExpectedVersion
    The right expected version to compare.

    Returns: `true` if `left` is greater than or equal to `right`; otherwise, `false`.

  • propertyKind
    public ExpectedVersionKind Kind { get; }

    Gets the category of version expectation.

  • propertyVersion
    public ConcurrencyVersion Version { get; }

    Gets the specific version value when `Kind` is `ExpectedVersionKind.Specific`.

  • fieldAny
    public static readonly ExpectedVersion Any

    Represents an expectation matching any version, effectively bypassing optimistic version checks.

  • fieldExists
    public static readonly ExpectedVersion Exists

    Represents an expectation that the target entity exists in storage with any non-zero version.

  • fieldNew
    public static readonly ExpectedVersion New

    Represents an expectation that the target entity does not yet exist in storage (version 0).

enum

ExpectedVersionKind

Assembly: EricksonLopez.Concurrency.Abstractions
public enum ExpectedVersionKind : byte

Specifies the expected version semantics for an optimistic concurrency operation.

Members (4)

  • fieldAny
    Any = 1

    Matches any version (disables optimistic version mismatch check).

  • fieldExists
    Exists = 3

    Expects that the target entity exists with any non-zero version.

  • fieldNew
    New = 2

    Expects that the target entity does not yet exist (version 0 / None).

  • fieldSpecific
    Specific = 0

    Matches an exact, specific numeric version. Note: This is the default state (0), which means `default(ExpectedVersion)` strictly expects version 0 (New/Uninitialized) by default.

interface

IConcurrencyAware

Assembly: EricksonLopez.Concurrency.Abstractions
public interface IConcurrencyAware

Defines a contract for domain entities, aggregates, or DTOs that encapsulate a concurrency token.

Members (1)

  • propertyConcurrencyToken
    IConcurrencyToken? ConcurrencyToken { get; }

    Gets the concurrency token associated with this instance, or `null` if no token has been assigned.

    When `null`, the default concurrency controller implementation treats this as an empty token (`ConcurrencyToken.None`).

interface

IConcurrencyChecker

Assembly: EricksonLopez.Concurrency.Abstractions
public interface IConcurrencyChecker

Defines a contract for zero-allocation synchronous evaluation of optimistic concurrency conditions and tokens.

Members (2)

  • methodCheckToken
    bool CheckToken(IConcurrencyToken expected, IConcurrencyToken actual, string entityId, string entityType, out ConcurrencyConflict? conflict)

    Evaluates whether an expected concurrency token matches the actual token found in storage or memory.

    expected: IConcurrencyToken
    The expected concurrency token constraint.
    actual: IConcurrencyToken
    The actual concurrency token found.
    entityId: string
    The unique identifier of the entity.
    entityType: string
    The type name or discriminator of the entity.
    conflict: out ConcurrencyConflict?
    When this method returns `false`, contains the populated conflict descriptor; otherwise, `null`.

    Returns: `true` if the tokens match; otherwise, `false`.

  • methodCheckVersion
    bool CheckVersion(ExpectedVersion expected, ConcurrencyVersion actual, string entityId, string entityType, out ConcurrencyConflict? conflict)

    Evaluates whether an expected version matches the actual version found in persistence or memory.

    expected: ExpectedVersion
    The expected version constraint.
    actual: ConcurrencyVersion
    The actual concurrency version found.
    entityId: string
    The unique identifier of the entity.
    entityType: string
    The type name or discriminator of the entity.
    conflict: out ConcurrencyConflict?
    When this method returns `false`, contains the populated conflict descriptor; otherwise, `null`.

    Returns: `true` if the version requirement is satisfied; otherwise, `false`.

interface

IConcurrencyConflictResolver<TEntity>

Assembly: EricksonLopez.Concurrency.Abstractions
public interface IConcurrencyConflictResolver<TEntity> where TEntity : class

Defines a contract for domain-specific or application-level optimistic concurrency conflict resolvers.

Remarks:

Type parameters: TEntity: The type of the domain entity or aggregate root.

Members (1)

  • methodResolveAsync
    ValueTask<ConflictResolution<TEntity>> ResolveAsync(TEntity proposedEntity, TEntity? currentDatabaseEntity, ConcurrencyConflict conflict, CancellationToken cancellationToken = default)

    Attempts to resolve a detected concurrency conflict between the proposed local entity state and the latest persistent state.

    proposedEntity: TEntity
    The local modified entity state that provoked the conflict.
    currentDatabaseEntity: TEntity?
    The current persistent entity state retrieved from storage, or `null` if deleted or missing.
    conflict: ConcurrencyConflict
    The conflict descriptor containing diagnostic and contextual metadata.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Returns: A value task representing the asynchronous operation. The task result contains the `ConflictResolution<TEntity>` outcome.

interface

IConcurrencyController

Assembly: EricksonLopez.Concurrency.Abstractions
public interface IConcurrencyController

Defines a core orchestrator contract for validating concurrency contracts and executing Compare-And-Swap (CAS) state mutations.

Members (4)

  • methodExecuteCasAsync<TEntity>
    ValueTask<CasResult<TEntity>> ExecuteCasAsync<TEntity>(TEntity entity, ExpectedVersion expected, string entityId, Func<TEntity, CancellationToken, TEntity> mutate, CancellationToken cancellationToken = default) where TEntity : class, IVersionedEntity

    Executes an in-memory optimistic Compare-And-Swap (CAS) state transition on a versioned entity using a synchronous mutation delegate.

    entity: TEntity
    The current entity instance before mutation.
    expected: ExpectedVersion
    The expected version constraint.
    entityId: string
    The unique identifier of the entity.
    mutate: Func<TEntity, CancellationToken, TEntity>
    The synchronous mutation delegate that produces the modified entity.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Returns: A value task representing the asynchronous operation. The task result contains the `CasResult<TEntity>` outcome.

    This method is a convenience overload that wraps the synchronous `mutate` delegate in a `ValueTask<TResult>`. It provides the exact same guarantees and semantics as the asynchronous counterpart. Use immutable types (e.g., records) in the delegate to prevent state corruption upon exceptions. Type parameters: TEntity: The type of the entity implementing `IVersionedEntity`. Exceptions: ArgumentNullException: `entity` or `mutate` is `null`; ArgumentException: `entityId` is `null`, empty, or whitespace; InvalidOperationException: A recursive/reentrant call was attempted on the same `entityId`, or an immutable entity did not advance its version; OperationCanceledException: `cancellationToken` has been cancelled; TimeoutException: The in-memory lock could not be acquired within the configured timeout, potentially due to a deadlock or a long-running operation

  • methodExecuteCasAsync<TEntity>
    ValueTask<CasResult<TEntity>> ExecuteCasAsync<TEntity>(TEntity entity, ExpectedVersion expected, string entityId, Func<TEntity, CancellationToken, ValueTask<TEntity>> mutate, CancellationToken cancellationToken = default) where TEntity : class, IVersionedEntity

    Executes an in-memory optimistic Compare-And-Swap (CAS) state transition on a versioned entity.

    entity: TEntity
    The current entity instance before mutation.
    expected: ExpectedVersion
    The expected version constraint.
    entityId: string
    The unique identifier of the entity.
    mutate: Func<TEntity, CancellationToken, ValueTask<TEntity>>
    The asynchronous mutation delegate that produces the modified entity.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Returns: A value task representing the asynchronous operation. The task result contains the `CasResult<TEntity>` outcome.

    Enforces per-entity mutual exclusion in memory. Invocations on the same `entityId` are strictly non-reentrant; attempting nested or recursive calls to `ExecuteCasAsync` for the same entity identifier within the same asynchronous flow will throw an `InvalidOperationException` to prevent deadlocks. If the target entity implements `IMutableVersionedEntity`, its `IMutableVersionedEntity.Version` is automatically advanced by the controller upon success. If the entity does not implement `IMutableVersionedEntity`, the `mutate` delegate must produce an entity whose version matches the incremented version. Warning (Data Corruption Risk): The `ExecuteCasAsync` method does not provide state rollback. If the `mutate` delegate modifies the entity and subsequently throws an exception, the entity remains in a partially modified state. Always pass a deep clone, use C# 9 `record` copy-semantics (with-expressions), or discard the entity reference on failure. Type parameters: TEntity: The type of the entity implementing `IVersionedEntity`. Exceptions: ArgumentNullException: `entity` or `mutate` is `null`; ArgumentException: `entityId` is `null`, empty, or whitespace; InvalidOperationException: A recursive/reentrant call was attempted on the same `entityId`, or an immutable entity did not advance its version; OperationCanceledException: `cancellationToken` has been cancelled; TimeoutException: The in-memory lock could not be acquired within the configured timeout, potentially due to a deadlock or a long-running operation

  • methodVerifyToken<TEntity>
    ConcurrencyConflict? VerifyToken<TEntity>(TEntity entity, IConcurrencyToken expected, string entityId) where TEntity : class, IConcurrencyAware

    Evaluates optimistic concurrency token compatibility against an entity instance.

    entity: TEntity
    The entity instance to verify.
    expected: IConcurrencyToken
    The expected concurrency token constraint.
    entityId: string
    The unique identifier of the entity.

    Returns: A `ConcurrencyConflict` if a token conflict is detected; otherwise, `null`.

    Type parameters: TEntity: The type of the entity implementing `IConcurrencyAware`. Exceptions: ArgumentNullException: `entity` or `expected` is `null`; ArgumentException: `entityId` is `null`, empty, or whitespace; ObjectDisposedException: The controller instance has been disposed; ConcurrencyException: A token conflict was detected and `ConcurrencyOptions.ThrowOnUnresolvedConflict` is `true`

  • methodVerifyVersion<TEntity>
    ConcurrencyConflict? VerifyVersion<TEntity>(TEntity entity, ExpectedVersion expected, string entityId) where TEntity : class, IVersionedEntity

    Evaluates optimistic version compatibility against an entity instance.

    entity: TEntity
    The entity instance to verify.
    expected: ExpectedVersion
    The expected version constraint.
    entityId: string
    The unique identifier of the entity.

    Returns: A `ConcurrencyConflict` if a version conflict is detected; otherwise, `null`.

    Type parameters: TEntity: The type of the entity implementing `IVersionedEntity`. Exceptions: ArgumentNullException: `entity` is `null`; ArgumentException: `entityId` is `null`, empty, or whitespace; ObjectDisposedException: The controller instance has been disposed; ConcurrencyException: A version conflict was detected and `ConcurrencyOptions.ThrowOnUnresolvedConflict` is `true`

interface

IConcurrencyToken

Assembly: EricksonLopez.Concurrency.Abstractions
public interface IConcurrencyToken : IEquatable<IConcurrencyToken>
Implements: IEquatable<IConcurrencyToken>

Defines a contract for an immutable concurrency token utilized in optimistic concurrency validation.

Members (3)

  • propertyIsEmpty
    bool IsEmpty { get; }

    Gets a value indicating whether the token represents an empty or uninitialized state.

  • propertyTokenKind
    string TokenKind { get; }

    Gets an opaque discriminator or type tag representing the token format (e.g., "RowVersion", "ETag", "Xmin", "Hash").

  • propertyValue
    string Value { get; }

    Gets the raw string representation of the concurrency token.

interface

IMutableVersionedEntity

Assembly: EricksonLopez.Concurrency.Abstractions
public interface IMutableVersionedEntity : IVersionedEntity
Implements: IVersionedEntity

Defines a contract for domain entities or aggregates whose numeric concurrency version can be mutated by the concurrency controller.

Members (1)

  • propertyVersion
    new long Version { get; set; }

    Gets or sets the current numeric concurrency version of the entity or aggregate.

interface

IVersionedEntity

Assembly: EricksonLopez.Concurrency.Abstractions
public interface IVersionedEntity

Defines a contract for domain entities or aggregates that maintain an explicit numeric concurrency version.

Members (1)

  • propertyVersion
    long Version { get; }

    Gets the current numeric concurrency version of the entity or aggregate.

interface

IVersionedEntity<TEntity>

Assembly: EricksonLopez.Concurrency.Abstractions
public interface IVersionedEntity<TEntity> : IVersionedEntity where TEntity : class
Implements: IVersionedEntity

Defines a strongly-typed contract for domain entities or aggregates that maintain a typed concurrency version.

Remarks:

Type parameters: TEntity: The target entity or aggregate type.

Members (1)

  • propertyTypedVersion
    ConcurrencyVersion<TEntity> TypedVersion { get; }

    Gets the strongly-typed concurrency version of this entity.

EricksonLopez.Concurrency.AspNetCore.DependencyInjection#

1
class

ConcurrencyAspNetCoreServiceCollectionExtensions

Assembly: EricksonLopez.Concurrency.AspNetCore
public static class ConcurrencyAspNetCoreServiceCollectionExtensions

Provides extension methods for registering ASP.NET Core concurrency integration services.

Members (1)

  • methodAddConcurrencyAspNetCore
    public static IServiceCollection AddConcurrencyAspNetCore(this IServiceCollection services)

    Registers ASP.NET Core concurrency integration dependencies into the specified `IServiceCollection`.

    services: this IServiceCollection
    The service collection to configure.

    Returns: The `IServiceCollection` instance so that calls can be chained.

EricksonLopez.Concurrency.AspNetCore.Extensions#

4
class

ConcurrencyConflictHttpResult

Assembly: EricksonLopez.Concurrency.AspNetCore
public sealed class ConcurrencyConflictHttpResult : IResult
Implements: IResult

Represents an `IResult` returned when an optimistic concurrency conflict occurs.

Members (4)

  • constructorConcurrencyConflictHttpResult
    public ConcurrencyConflictHttpResult(ConcurrencyConflict conflict, string? instance = null)

    Initializes a new instance of the `ConcurrencyConflictHttpResult` class.

    conflict: ConcurrencyConflict
    The concurrency conflict descriptor.
    instance: string?
    The optional request URI path.

    Exceptions: ArgumentNullException: `conflict` is `null`

  • methodExecuteAsync
    public async Task ExecuteAsync(HttpContext httpContext)

    Inherits documentation from base type or interface.

    httpContext: HttpContext

    Exceptions: ArgumentNullException: `httpContext` is `null`

  • propertyConflict
    public ConcurrencyConflict Conflict { get; }

    Gets the conflict descriptor.

  • propertyInstance
    public string? Instance { get; }

    Gets the optional request URI path.

class

ConcurrencyHttpExtensions

Assembly: EricksonLopez.Concurrency.AspNetCore
public static class ConcurrencyHttpExtensions

Provides extension methods on `HttpRequest` and `HttpResponse` for managing concurrency ETags and precondition headers.

Members (6)

  • methodGetExpectedConcurrencyToken
    public static ConcurrencyToken? GetExpectedConcurrencyToken(this HttpRequest request)

    Extracts the expected concurrency token from the incoming HTTP request's `If-Match` or `If-None-Match` headers.

    request: this HttpRequest
    The incoming HTTP request.

    Returns: The extracted `ConcurrencyToken`, or `null` if no matching ETag header was supplied.

    Exceptions: ArgumentNullException: `request` is `null`

  • methodGetExpectedConcurrencyVersion
    public static ExpectedVersion? GetExpectedConcurrencyVersion(this HttpRequest request)

    Extracts the expected numeric concurrency version from the incoming HTTP request's `If-Match` or `If-None-Match` headers.

    request: this HttpRequest
    The incoming HTTP request.

    Returns: The extracted `ExpectedVersion` constraint, or `null` if no numeric version ETag header was supplied.

    Exceptions: ArgumentNullException: `request` is `null`

  • methodSetConcurrencyETag
    public static void SetConcurrencyETag(this HttpResponse response, ConcurrencyToken token, bool isWeak = true)

    Sets the HTTP `ETag` response header formatted with the specified `ConcurrencyToken`.

    response: this HttpResponse
    The outgoing HTTP response.
    token: ConcurrencyToken
    The concurrency token value struct.
    isWeak: bool
    A value indicating whether to emit a weak validator (`W/"..."`).

    Exceptions: ArgumentNullException: `response` is `null`

  • methodSetConcurrencyETag
    public static void SetConcurrencyETag(this HttpResponse response, ConcurrencyVersion version, bool isWeak = true)

    Sets the HTTP `ETag` response header formatted with the specified `ConcurrencyVersion`.

    response: this HttpResponse
    The outgoing HTTP response.
    version: ConcurrencyVersion
    The concurrency version.
    isWeak: bool
    A value indicating whether to emit a weak validator (`W/"..."`).

    Exceptions: ArgumentNullException: `response` is `null`

  • methodSetConcurrencyETag
    public static void SetConcurrencyETag(this HttpResponse response, IConcurrencyToken token, bool isWeak = true)

    Sets the HTTP `ETag` response header formatted with the specified `IConcurrencyToken`.

    response: this HttpResponse
    The outgoing HTTP response.
    token: IConcurrencyToken
    The concurrency token.
    isWeak: bool
    A value indicating whether to emit a weak validator (`W/"..."`).

    Exceptions: ArgumentNullException: `response` or `token` is `null`

  • methodSetConcurrencyETag
    public static void SetConcurrencyETag(this HttpResponse response, long version, bool isWeak = true)

    Sets the HTTP `ETag` response header formatted with the specified numeric version.

    response: this HttpResponse
    The outgoing HTTP response.
    version: long
    The numeric version value.
    isWeak: bool
    A value indicating whether to emit a weak validator (`W/"..."`).

    Exceptions: ArgumentNullException: `response` is `null`

class

ConcurrencyMiddlewareExtensions

Assembly: EricksonLopez.Concurrency.AspNetCore
public static class ConcurrencyMiddlewareExtensions

Provides extension methods for registering concurrency middleware into an `IApplicationBuilder`.

Members (1)

  • methodUseConcurrencyConflictHandling
    public static IApplicationBuilder UseConcurrencyConflictHandling(this IApplicationBuilder app)

    Adds the `ConcurrencyConflictMiddleware` to the application pipeline to automatically convert `ConcurrencyException` into RFC 7807 HTTP 409 Conflict responses.

    app: this IApplicationBuilder
    The application builder.

    Returns: The application builder instance for chaining.

    Exceptions: ArgumentNullException: `app` is `null`

class

ConcurrencyResultExtensions

Assembly: EricksonLopez.Concurrency.AspNetCore
public static class ConcurrencyResultExtensions

Provides extension methods for constructing minimal API `IResult` responses for concurrency conflicts.

Members (1)

  • methodConcurrencyConflict
    public static IResult ConcurrencyConflict(this IResultExtensions resultExtensions, ConcurrencyConflict conflict, string? instance = null)

    Returns an `IResult` representing an RFC 7807 compliant HTTP 409 Conflict with concurrency metadata and ETag headers.

    resultExtensions: this IResultExtensions
    The result extensions factory.
    conflict: ConcurrencyConflict
    The conflict descriptor.
    instance: string?
    The optional request URI path.

    Returns: A new `IResult` configured with the conflict details.

    Exceptions: ArgumentNullException: `resultExtensions` or `conflict` is `null`

EricksonLopez.Concurrency.AspNetCore.Middleware#

1
class

ConcurrencyConflictMiddleware

Assembly: EricksonLopez.Concurrency.AspNetCore
public sealed partial class ConcurrencyConflictMiddleware

Intercepts unhandled `ConcurrencyException` instances in the HTTP pipeline and writes RFC 7807 compliant HTTP 409 Conflict responses.

Members (2)

  • constructorConcurrencyConflictMiddleware
    public ConcurrencyConflictMiddleware(RequestDelegate next, ILogger<ConcurrencyConflictMiddleware>? logger = null)

    Initializes a new instance of the `ConcurrencyConflictMiddleware` class.

    next: RequestDelegate
    The next middleware in the execution pipeline.
    logger: ILogger<ConcurrencyConflictMiddleware>?
    An optional logger instance.

    Exceptions: ArgumentNullException: `next` is `null`

  • methodInvokeAsync
    public async Task InvokeAsync(HttpContext context)

    Executes the middleware pipeline logic.

    context: HttpContext
    The current HTTP context.

    Returns: A task representing the asynchronous middleware execution.

    Exceptions: ArgumentNullException: `context` is `null`

EricksonLopez.Concurrency.AspNetCore.Models#

1
class

ConcurrencyProblemDetails

Assembly: EricksonLopez.Concurrency.AspNetCore
public sealed class ConcurrencyProblemDetails : ProblemDetails
Inherits: ProblemDetails

Represents an RFC 7807 compliant `ProblemDetails` payload describing an optimistic concurrency conflict.

Members (10)

  • constructorConcurrencyProblemDetails
    public ConcurrencyProblemDetails()

    Initializes a new instance of the `ConcurrencyProblemDetails` class.

  • methodFrom
    public static ConcurrencyProblemDetails From(ConcurrencyConflict conflict, string? instance = null)

    Creates a new `ConcurrencyProblemDetails` from a domain `ConcurrencyConflict`.

    conflict: ConcurrencyConflict
    The conflict descriptor.
    instance: string?
    The optional request URI path that triggered the conflict.

    Returns: A configured `ConcurrencyProblemDetails` instance.

    Exceptions: ArgumentNullException: `conflict` is `null`

  • propertyActualToken
    public string? ActualToken { get; set; }

    Gets or sets the actual concurrency token found in persistent storage, if applicable.

  • propertyActualVersion
    public string? ActualVersion { get; set; }

    Gets or sets the actual version value found in persistent storage, if applicable.

  • propertyClassification
    public string? Classification { get; set; }

    Gets or sets the retryability classification of the conflict.

  • propertyConflictType
    public string? ConflictType { get; set; }

    Gets or sets the specific concurrency conflict category discriminator.

  • propertyEntityId
    public string? EntityId { get; set; }

    Gets or sets the unique identifier of the conflicting entity.

  • propertyEntityType
    public string? EntityType { get; set; }

    Gets or sets the type name of the conflicting entity.

  • propertyExpectedToken
    public string? ExpectedToken { get; set; }

    Gets or sets the expected concurrency token, if applicable.

  • propertyExpectedVersion
    public string? ExpectedVersion { get; set; }

    Gets or sets the expected version value, if applicable.

EricksonLopez.Concurrency.Controllers#

2
class

ConcurrencyController

Assembly: EricksonLopez.Concurrency
public sealed class ConcurrencyController : IConcurrencyController, IDisposable, IAsyncDisposable
Implements: IAsyncDisposable, IConcurrencyController, IDisposable

Coordinates optimistic concurrency validations and in-memory Compare-And-Swap (CAS) state transitions.

Members (9)

  • constructorConcurrencyController
    public ConcurrencyController()

    Initializes a new instance of the `ConcurrencyController` class with default settings.

  • constructorConcurrencyController
    public ConcurrencyController(ConcurrencyOptions? options)

    Initializes a new instance of the `ConcurrencyController` class with the specified options.

    options: ConcurrencyOptions?
    Configuration options governing conflict handling and diagnostics.
  • constructorConcurrencyController
    public ConcurrencyController(IConcurrencyChecker? checker)

    Initializes a new instance of the `ConcurrencyController` class with the specified checker.

    checker: IConcurrencyChecker?
    The concurrency checker used to evaluate version and token constraints, or `null` to use `OptimisticConcurrencyChecker.Instance`.
  • constructorConcurrencyController
    public ConcurrencyController(IConcurrencyChecker? checker, ConcurrencyOptions? options)

    Initializes a new instance of the `ConcurrencyController` class.

    checker: IConcurrencyChecker?
    The concurrency checker used to evaluate version and token constraints, or `null` to use `OptimisticConcurrencyChecker.Instance`.
    options: ConcurrencyOptions?
    Configuration options governing conflict handling and diagnostics.
  • methodDispose
    public void Dispose()

    Releases the resources used by this instance.

  • methodDisposeAsync
    public ValueTask DisposeAsync()

    Asynchronously releases the resources used by this instance.

    Returns: A value task representing the asynchronous disposal operation.

  • methodExecuteCasAsync<TEntity>
    public async ValueTask<CasResult<TEntity>> ExecuteCasAsync<TEntity>(TEntity entity, ExpectedVersion expected, string entityId, Func<TEntity, CancellationToken, ValueTask<TEntity>> mutate, CancellationToken cancellationToken = default) where TEntity : class, IVersionedEntity

    Executes an in-memory optimistic Compare-And-Swap (CAS) state transition on a versioned entity.

    entity: TEntity
    The current entity instance before mutation.
    expected: ExpectedVersion
    The expected version constraint.
    entityId: string
    The unique identifier of the entity.
    mutate: Func<TEntity, CancellationToken, ValueTask<TEntity>>
    The asynchronous mutation delegate that produces the modified entity.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Returns: A value task representing the asynchronous operation. The task result contains the `CasResult<TEntity>` outcome.

    Enforces per-entity mutual exclusion in memory. Invocations on the same `entityId` are strictly non-reentrant; attempting nested or recursive calls to `ExecuteCasAsync` for the same entity identifier within the same asynchronous flow will throw an `InvalidOperationException` to prevent deadlocks. If the target entity implements `IMutableVersionedEntity`, its `IMutableVersionedEntity.Version` is automatically advanced by the controller upon success. If the entity does not implement `IMutableVersionedEntity`, the `mutate` delegate must produce an entity whose version matches the incremented version. Warning (Data Corruption Risk): The `ExecuteCasAsync` method does not provide state rollback. If the `mutate` delegate modifies the entity and subsequently throws an exception, the entity remains in a partially modified state. Always pass a deep clone, use C# 9 `record` copy-semantics (with-expressions), or discard the entity reference on failure. Type parameters: TEntity: The type of the entity implementing `IVersionedEntity`. Exceptions: ArgumentNullException: `entity` or `mutate` is `null`; ArgumentException: `entityId` is `null`, empty, or whitespace; ObjectDisposedException: This controller instance has already been disposed; InvalidOperationException: A reentrant call was detected for `entityId`, or an immutable entity did not advance its version; OperationCanceledException: The cancellation token was canceled; TimeoutException: The in-memory lock could not be acquired within the configured timeout

  • methodVerifyToken<TEntity>
    public ConcurrencyConflict? VerifyToken<TEntity>(TEntity entity, IConcurrencyToken expected, string entityId) where TEntity : class, IConcurrencyAware

    Evaluates optimistic concurrency token compatibility against an entity instance.

    entity: TEntity
    The entity instance to verify.
    expected: IConcurrencyToken
    The expected concurrency token constraint.
    entityId: string
    The unique identifier of the entity.

    Returns: A `ConcurrencyConflict` if a token conflict is detected; otherwise, `null`.

    Type parameters: TEntity: The type of the entity implementing `IConcurrencyAware`. Exceptions: ArgumentNullException: `entity` or `expected` is `null`; ArgumentException: `entityId` is `null`, empty, or whitespace; ObjectDisposedException: This controller instance has already been disposed; ConcurrencyException: A concurrency conflict occurred and `ConcurrencyOptions.ThrowOnUnresolvedConflict` is `true`

  • methodVerifyVersion<TEntity>
    public ConcurrencyConflict? VerifyVersion<TEntity>(TEntity entity, ExpectedVersion expected, string entityId) where TEntity : class, IVersionedEntity

    Evaluates optimistic version compatibility against an entity instance.

    entity: TEntity
    The entity instance to verify.
    expected: ExpectedVersion
    The expected version constraint.
    entityId: string
    The unique identifier of the entity.

    Returns: A `ConcurrencyConflict` if a version conflict is detected; otherwise, `null`.

    Type parameters: TEntity: The type of the entity implementing `IVersionedEntity`. Exceptions: ArgumentNullException: `entity` is `null`; ArgumentException: `entityId` is `null`, empty, or whitespace; ObjectDisposedException: This controller instance has already been disposed; ConcurrencyException: A concurrency conflict occurred and `ConcurrencyOptions.ThrowOnUnresolvedConflict` is `true`

class

OptimisticConcurrencyChecker

Assembly: EricksonLopez.Concurrency
public sealed class OptimisticConcurrencyChecker : IConcurrencyChecker
Implements: IConcurrencyChecker

Provides zero-allocation synchronous evaluation of optimistic concurrency conditions and tokens.

Members (3)

  • methodCheckToken
    public bool CheckToken(IConcurrencyToken expected, IConcurrencyToken actual, string entityId, string entityType, out ConcurrencyConflict? conflict)

    Evaluates whether an expected concurrency token matches the actual token found in storage or memory.

    expected: IConcurrencyToken
    The expected concurrency token constraint.
    actual: IConcurrencyToken
    The actual concurrency token found.
    entityId: string
    The unique identifier of the entity.
    entityType: string
    The type name or discriminator of the entity.
    conflict: out ConcurrencyConflict?
    When this method returns `false`, contains the populated conflict descriptor; otherwise, `null`.

    Returns: `true` if the tokens match; otherwise, `false`.

  • methodCheckVersion
    public bool CheckVersion(ExpectedVersion expected, ConcurrencyVersion actual, string entityId, string entityType, out ConcurrencyConflict? conflict)

    Evaluates whether an expected version matches the actual version found in persistence or memory.

    expected: ExpectedVersion
    The expected version constraint.
    actual: ConcurrencyVersion
    The actual concurrency version found.
    entityId: string
    The unique identifier of the entity.
    entityType: string
    The type name or discriminator of the entity.
    conflict: out ConcurrencyConflict?
    When this method returns `false`, contains the populated conflict descriptor; otherwise, `null`.

    Returns: `true` if the version requirement is satisfied; otherwise, `false`.

  • fieldInstance
    public static readonly OptimisticConcurrencyChecker Instance

    Gets the shared singleton instance of `OptimisticConcurrencyChecker`.

EricksonLopez.Concurrency.Dapper#

3
class

ConcurrencyDapperExtensions

Assembly: EricksonLopez.Concurrency.Dapper
public static class ConcurrencyDapperExtensions

Provides extension methods for `IDbConnection` to execute optimistic concurrency commands with automated conflict detection.

Members (2)

  • methodExecuteOptimisticAsync
    public static async Task<ConcurrencyConflict?> ExecuteOptimisticAsync(this IDbConnection connection, string sql, object? param, ExpectedVersion expectedVersion, string entityId, string entityType, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default)

    Executes a parameterized SQL command and evaluates whether the affected row count satisfies the optimistic version condition.

    connection: this IDbConnection
    The database connection to execute the command against.
    sql: string
    The SQL statement containing optimistic WHERE conditions (e.g. `WHERE id = @Id AND version = @ExpectedVersion`).
    param: object?
    The command parameters to pass to the query.
    expectedVersion: ExpectedVersion
    The expected version constraint.
    entityId: string
    The unique identifier of the entity being updated.
    entityType: string
    The type name of the entity being updated.
    transaction: IDbTransaction?
    The active database transaction, if any.
    commandTimeout: int?
    The command timeout in seconds, or `null` to use the default timeout.
    commandType: CommandType?
    The type of command to execute.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Returns: A task representing the asynchronous operation. The task result contains a `ConcurrencyConflict` if no rows were modified; otherwise, `null` indicating success.

    Exceptions: ArgumentNullException: `connection` is `null`; ArgumentException: `sql` is `null` or whitespace; InvalidOperationException: The optimistic update affected more than one row

  • methodExecuteOptimisticTokenAsync
    public static async Task<ConcurrencyConflict?> ExecuteOptimisticTokenAsync(this IDbConnection connection, string sql, object? param, IConcurrencyToken expectedToken, string entityId, string entityType, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default)

    Executes a parameterized SQL command and evaluates whether the affected row count satisfies the optimistic token condition.

    connection: this IDbConnection
    The database connection to execute the command against.
    sql: string
    The SQL statement containing optimistic WHERE conditions for concurrency tokens.
    param: object?
    The command parameters to pass to the query.
    expectedToken: IConcurrencyToken
    The expected concurrency token constraint.
    entityId: string
    The unique identifier of the entity being updated.
    entityType: string
    The type name of the entity being updated.
    transaction: IDbTransaction?
    The active database transaction, if any.
    commandTimeout: int?
    The command timeout in seconds, or `null` to use the default timeout.
    commandType: CommandType?
    The type of command to execute.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Returns: A task representing the asynchronous operation. The task result contains a `ConcurrencyConflict` if no rows were modified; otherwise, `null` indicating success.

    Exceptions: ArgumentNullException: `connection` or `expectedToken` is `null`; ArgumentException: `sql` is `null` or whitespace; InvalidOperationException: The optimistic update affected more than one row

class

OptimisticUpdateBuilder

Assembly: EricksonLopez.Concurrency.Dapper
public static class OptimisticUpdateBuilder

Provides helper methods for generating SQL UPDATE statements with optimistic concurrency and multi-tenancy predicates.

Members (1)

  • methodBuildVersionedUpdate
    public static string BuildVersionedUpdate(string tableName, string setClauses, string idColumn = "", string versionColumn = "", string idParam = "", string versionParam = "", string? tenantColumn = null, string? tenantParam = null)

    Generates an optimistic version-incrementing SQL UPDATE command.

    tableName: string
    The target database table name.
    setClauses: string
    The column assignment expressions (e.g., `name = @Name, status = @Status`).
    idColumn: string
    The name of the identifier column. Defaults to `"id"`.
    versionColumn: string
    The name of the concurrency version column. Defaults to `"version"`.
    idParam: string
    The name of the identifier parameter. Defaults to `"Id"`.
    versionParam: string
    The name of the expected version parameter. Defaults to `"ExpectedVersion"`.
    tenantColumn: string?
    The optional name of the tenant isolation column.
    tenantParam: string?
    The optional name of the tenant isolation parameter.

    Returns: A generated SQL UPDATE statement containing optimistic concurrency predicates.

    Exceptions: ArgumentException: `tableName`, `setClauses`, `idColumn`, or `versionColumn` is `null` or whitespace or contains invalid identifier characters

class

UInt32BigIntTypeHandler

Assembly: EricksonLopez.Concurrency.Dapper
public sealed class UInt32BigIntTypeHandler : SqlMapper.TypeHandler<uint>
Inherits: SqlMapper.TypeHandler<uint>

Maps C# `uint` optimistic concurrency counters (`RowVersion` / `xmin`) to SQL `BIGINT` (`DbType.Int64`) with strict arithmetic overflow validation on hydration, preventing `DbType.UInt32` driver rejections.

Members (2)

  • methodParse
    public override uint Parse(object value)

    Inherits documentation from base type or interface.

    value: object
  • methodSetValue
    public override void SetValue(IDbDataParameter parameter, uint value)

    Inherits documentation from base type or interface.

    parameter: IDbDataParameter
    value: uint

EricksonLopez.Concurrency.Dapper.DependencyInjection#

1
class

DapperConcurrencyServiceCollectionExtensions

Assembly: EricksonLopez.Concurrency.Dapper
public static class DapperConcurrencyServiceCollectionExtensions

Provides extension methods for registering Dapper concurrency adapters into an `IServiceCollection`.

Members (1)

  • methodAddEricksonLopezConcurrencyDapper
    public static IServiceCollection AddEricksonLopezConcurrencyDapper(this IServiceCollection services)

    Registers Dapper optimistic concurrency adapter services.

    services: this IServiceCollection
    The `IServiceCollection` to add services to.

    Returns: The `IServiceCollection` instance so that additional calls can be chained.

    Exceptions: ArgumentNullException: `services` is `null`

EricksonLopez.Concurrency.DependencyInjection#

2
class

ConcurrencyOptions

Assembly: EricksonLopez.Concurrency
public sealed class ConcurrencyOptions

Specifies configuration options and default behaviors for the concurrency framework.

Members (9)

  • methodCalculateDefaultStripeCount
    public static int CalculateDefaultStripeCount(int processorCount)

    Calculates the default stripe count based on the specified processor count.

    processorCount: int
    The number of available processors.

    Returns: The calculated stripe count, with a minimum of 256.

  • propertyDefaultConflictClassification
    public ConcurrencyConflictClassification DefaultConflictClassification { get; set; }

    Gets or sets the default conflict classification assigned when generating generic version mismatch conflicts.

    The default value is `ConcurrencyConflictClassification.Transient`.

  • propertyDefaultMaxAcquisitionTimeout
    public TimeSpan DefaultMaxAcquisitionTimeout { get; set; }

    Gets or sets the default maximum time to wait when acquiring an optimistic in-memory lock.

    The default value is 10 seconds. If a lock cannot be acquired within this time, a `TimeoutException` is thrown to prevent deadlocks.

  • propertyDefaultMaxExecutionTimeout
    public TimeSpan DefaultMaxExecutionTimeout { get; set; }

    Gets or sets the default maximum time a mutation delegate is allowed to execute while holding the in-memory lock.

    The default value is 30 seconds. If the delegate execution exceeds this time, the provided cancellation token will be cancelled to prevent thread-pool starvation.

  • propertyDefaultResolutionStrategy
    public ConflictResolutionStrategy DefaultResolutionStrategy { get; set; }

    Gets or sets the default strategy applied when a concurrency conflict is detected.

    The default value is `ConflictResolutionStrategy.Reject`.

  • propertyEnableDiagnostics
    public bool EnableDiagnostics { get; set; }

    Gets or sets a value indicating whether OpenTelemetry activity tracking and metrics are enabled.

    The default value is `true`.

  • propertyRecordDetailedActivityTags
    public bool RecordDetailedActivityTags { get; set; }

    Gets or sets a value indicating whether detailed contextual tags are attached to OpenTelemetry activities.

    The default value is `true`.

  • propertyStripeCount
    public int StripeCount { get; set; }

    Gets or sets the number of stripes (partitions) used by the concurrency controller to shard internal locks.

    The default value is calculated as `Environment.ProcessorCount` * 8, with a minimum of 256. Higher values reduce false-sharing contention in highly concurrent systems at the cost of slight memory overhead.

  • propertyThrowOnUnresolvedConflict
    public bool ThrowOnUnresolvedConflict { get; set; }

    Gets or sets a value indicating whether unresolved conflicts throw a `ConcurrencyException` automatically.

    The default value is `false` (returns conflict model for caller inspection).

class

ConcurrencyServiceCollectionExtensions

Assembly: EricksonLopez.Concurrency
public static class ConcurrencyServiceCollectionExtensions

Provides extension methods for registering concurrency services into an `IServiceCollection`.

Members (2)

  • methodAddConflictResolver<TEntity, TResolver>
    public static IServiceCollection AddConflictResolver<TEntity, TResolver>(this IServiceCollection services) where TEntity : class where TResolver : class, IConcurrencyConflictResolver<TEntity>

    Registers a custom domain-specific conflict resolver for the specified entity type.

    services: this IServiceCollection
    The `IServiceCollection` to add the resolver to.

    Returns: The `IServiceCollection` instance so that additional calls can be chained.

    Type parameters: TEntity: The type of the domain entity or aggregate root.; TResolver: The type of the custom conflict resolver implementation. Exceptions: ArgumentNullException: `services` is `null`

  • methodAddEricksonLopezConcurrency
    public static IServiceCollection AddEricksonLopezConcurrency(this IServiceCollection services, Action<ConcurrencyOptions>? configure = null)

    Registers core concurrency services including the default concurrency checker, controller, and rejection resolver.

    services: this IServiceCollection
    The `IServiceCollection` to add services to.
    configure: Action<ConcurrencyOptions>?
    An optional action delegate to configure `ConcurrencyOptions`.

    Returns: The `IServiceCollection` instance so that additional calls can be chained.

    Exceptions: ArgumentNullException: `services` is `null`

EricksonLopez.Concurrency.Diagnostics#

1
class

ConcurrencyDiagnostics

Assembly: EricksonLopez.Concurrency
public static class ConcurrencyDiagnostics

Provides OpenTelemetry activities, meters, counters, and metrics instrumentation for concurrency operations.

Members (13)

  • methodRecordConflict
    public static void RecordConflict(Activity? activity, string conflictType, string entityType)

    Records a concurrency conflict event on the specified activity and increments metrics.

    activity: Activity?
    The active tracing activity, or `null`.
    conflictType: string
    The category or discriminator of the conflict.
    entityType: string
    The type name of the target entity.
  • methodRecordMerge
    public static void RecordMerge(Activity? activity, string entityType, string? strategy = null)

    Records a domain or strategy conflict merge reconciliation and increments the merges metric counter.

    activity: Activity?
    The active tracing activity, or `null`.
    entityType: string
    The type name of the target entity.
    strategy: string?
    The name of the resolution strategy applied.
  • methodRecordSuccess
    public static void RecordSuccess(Activity? activity, string entityType)

    Records a successful concurrency check or state mutation on the specified activity and increments metrics.

    activity: Activity?
    The active tracing activity, or `null`.
    entityType: string
    The type name of the target entity.
  • methodStartActivity
    public static Activity? StartActivity(string operationName, string entityType, string entityId)

    Starts a new OpenTelemetry tracing activity for a concurrency operation.

    operationName: string
    The name of the concurrency operation.
    entityType: string
    The type name of the target entity.
    entityId: string
    The unique identifier of the target entity.

    Returns: The started `Activity` if tracing is enabled; otherwise, `null`.

  • fieldActivitySource
    public static readonly ActivitySource ActivitySource

    Gets the `Diagnostics.ActivitySource` for distributed tracing instrumentation.

  • fieldConflictsCounter
    public static readonly Counter<long> ConflictsCounter

    Gets the counter measuring the total number of optimistic concurrency conflicts detected.

  • fieldFailuresCounter
    public static readonly Counter<long> FailuresCounter

    Gets the counter measuring the total number of failed concurrency operations.

  • fieldMergesCounter
    public static readonly Counter<long> MergesCounter

    Gets the counter measuring the total number of domain conflict merges executed.

  • fieldMeter
    public static readonly Meter Meter

    Gets the `Metrics.Meter` for metrics collection and telemetry.

  • fieldOperationDurationHistogram
    public static readonly Histogram<double> OperationDurationHistogram

    Gets the histogram measuring the duration in milliseconds of concurrency evaluations and state mutations.

  • fieldSourceName
    public const string SourceName

    Specifies the instrumentation name for OpenTelemetry activity and meter sources.

  • fieldSuccessesCounter
    public static readonly Counter<long> SuccessesCounter

    Gets the counter measuring the total number of successful concurrency operations.

  • fieldVersion
    public const string Version

    Specifies the current semantic version of the instrumentation source.

EricksonLopez.Concurrency.MariaDb#

3
class

MariaDbConcurrencyErrorClassifier

Assembly: EricksonLopez.Concurrency.MariaDb
public static class MariaDbConcurrencyErrorClassifier

Classifies MariaDB error codes, deadlocks, lock wait timeouts, and unique constraint violations.

Members (5)

  • methodIsDeadlock
    public static bool IsDeadlock(Exception? exception)

    Determines whether the specified exception represents a MariaDB deadlock (Error 1213).

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the error represents a deadlock; otherwise, `false`.

  • methodIsLockTimeout
    public static bool IsLockTimeout(Exception? exception)

    Determines whether the specified exception represents a lock wait timeout (Error 1205).

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the error represents a lock timeout; otherwise, `false`.

  • methodIsTransient
    public static bool IsTransient(Exception? exception)

    Determines whether the specified exception represents a transient failure suitable for retry.

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the error is transient; otherwise, `false`.

  • methodIsUniqueViolation
    public static bool IsUniqueViolation(Exception? exception)

    Determines whether the specified exception represents a duplicate key violation (Error 1062).

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the error represents a duplicate entry; otherwise, `false`.

  • methodToConcurrencyConflict
    public static ConcurrencyConflict? ToConcurrencyConflict(MySqlException exception, string entityId, string entityType, string? operation = null)

    Translates a `MySqlException` into a structured `ConcurrencyConflict`.

    exception: MySqlException
    The MariaDB exception to translate.
    entityId: string
    The unique identifier of the entity involved.
    entityType: string
    The type name of the entity involved.
    operation: string?
    The operation name being executed.

    Returns: A populated `ConcurrencyConflict` if recognized as a concurrency error; otherwise, `null`.

    Exceptions: ArgumentNullException: `exception` is `null`

class

MariaDbLockExtensions

Assembly: EricksonLopez.Concurrency.MariaDb
public static class MariaDbLockExtensions

Provides extension methods for appending MariaDB locking clauses to query strings.

Members (2)

  • methodWithMariaDbLock
    public static string WithMariaDbLock(this string sqlQuery, MariaDbLockMode lockMode)

    Appends the appropriate MariaDB locking clause to the specified SELECT query.

    sqlQuery: this string
    The base SQL select query.
    lockMode: MariaDbLockMode
    The MariaDB lock mode to append.

    Returns: The modified query with the locking clause attached.

    Exceptions: ArgumentException: `sqlQuery` is `null` or whitespace; ArgumentOutOfRangeException: `lockMode` is not a valid `MariaDbLockMode`

  • methodWithMariaDbLockWait
    public static string WithMariaDbLockWait(this string sqlQuery, int timeoutSeconds)

    Appends a `FOR UPDATE WAIT [seconds]` clause to the specified SELECT query.

    sqlQuery: this string
    The base SQL select query.
    timeoutSeconds: int
    The lock wait timeout in seconds.

    Returns: The modified query with the timed lock clause attached.

    Exceptions: ArgumentException: `sqlQuery` is `null` or whitespace; ArgumentOutOfRangeException: `timeoutSeconds` is negative

enum

MariaDbLockMode

Assembly: EricksonLopez.Concurrency.MariaDb
public enum MariaDbLockMode

Specifies MariaDB locking clauses for pessimistic record locking.

Members (4)

  • fieldForUpdate
    ForUpdate

    Exclusive write lock (`FOR UPDATE`).

  • fieldForUpdateNowait
    ForUpdateNowait

    Exclusive write lock failing immediately if locked (`FOR UPDATE NOWAIT`).

  • fieldForUpdateSkipLocked
    ForUpdateSkipLocked

    Exclusive write lock skipping locked records (`FOR UPDATE SKIP LOCKED`).

  • fieldLockInShareMode
    LockInShareMode

    Shared read lock (`LOCK IN SHARE MODE`).

EricksonLopez.Concurrency.MariaDb.DependencyInjection#

1
class

MariaDbConcurrencyServiceCollectionExtensions

Assembly: EricksonLopez.Concurrency.MariaDb
public static class MariaDbConcurrencyServiceCollectionExtensions

Provides extension methods for registering MariaDB concurrency services into an `IServiceCollection`.

Members (1)

  • methodAddEricksonLopezConcurrencyMariaDb
    public static IServiceCollection AddEricksonLopezConcurrencyMariaDb(this IServiceCollection services)

    Registers MariaDB concurrency dialect services into the dependency injection container.

    services: this IServiceCollection
    The `IServiceCollection` to add services to.

    Returns: The `IServiceCollection` instance so that additional calls can be chained.

    Exceptions: ArgumentNullException: `services` is `null`

EricksonLopez.Concurrency.Mediator#

3
class

ConcurrencyBehavior<TRequest, TResponse>

Assembly: EricksonLopez.Concurrency.Mediator
public sealed class ConcurrencyBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
Implements: IPipelineBehavior<TRequest, TResponse>

Represents an observability pipeline behavior intercepting `IConcurrencyAwareRequest` commands to track concurrency telemetry, distributed trace spans, and metric counters.

Remarks:

Important Architectural Notice: This pipeline behavior is strictly focused on observability and telemetry (OpenTelemetry `concurrency.mediator.handle` activity tags and metric tracking). It does not automatically verify or enforce entity version preconditions against persistent storage. Optimistic version enforcement and CAS state transitions must be executed explicitly inside the request handler using an injected `IConcurrencyController`. Type parameters: TRequest: The request type being processed.; TResponse: The response type returned by the downstream pipeline.

Members (1)

  • methodHandle<TNext>
    public async ValueTask<TResponse> Handle<TNext>(TRequest request, TNext next, CancellationToken cancellationToken) where TNext : struct, INext<TResponse>

    Inherits documentation from base type or interface.

    request: TRequest
    next: TNext
    cancellationToken: CancellationToken
interface

IConcurrencyAwareRequest

Assembly: EricksonLopez.Concurrency.Mediator
public interface IConcurrencyAwareRequest

Defines a contract for mediator commands or requests that declare explicit optimistic concurrency constraints.

Members (2)

  • propertyConcurrencyToken
    IConcurrencyToken? ConcurrencyToken { get; }

    Gets the expected concurrency token for optimistic verification, if specified.

  • propertyExpectedVersion
    ExpectedVersion? ExpectedVersion { get; }

    Gets the expected numeric version for optimistic verification, if specified.

interface

IConcurrencyAwareRequest<TResponse>

Assembly: EricksonLopez.Concurrency.Mediator
public interface IConcurrencyAwareRequest<TResponse> : ICommand<TResponse>, IConcurrencyAwareRequest
Implements: ICommand<TResponse>, IConcurrencyAwareRequest

Defines a strongly-typed contract for mediator commands returning `TResponse` that declare explicit concurrency constraints.

Remarks:

Type parameters: TResponse: The response type returned by the command handler.

Members (0)

This type declares 0 public members (e.g. marker interface or empty enum/record).

EricksonLopez.Concurrency.Mediator.DependencyInjection#

1
class

ConcurrencyMediatorServiceCollectionExtensions

Assembly: EricksonLopez.Concurrency.Mediator
public static class ConcurrencyMediatorServiceCollectionExtensions

Provides extension methods for registering the mediator concurrency pipeline behavior into an `IServiceCollection`.

Members (1)

  • methodAddConcurrencyMediatorBehavior
    public static IServiceCollection AddConcurrencyMediatorBehavior(this IServiceCollection services)

    Registers the `ConcurrencyBehavior<TRequest, TResponse>` open generic pipeline behavior in the service collection.

    services: this IServiceCollection
    The `IServiceCollection` to add services to.

    Returns: The `IServiceCollection` instance so that additional calls can be chained.

EricksonLopez.Concurrency.MySql#

3
class

MySqlConcurrencyErrorClassifier

Assembly: EricksonLopez.Concurrency.MySql
public static class MySqlConcurrencyErrorClassifier

Classifies MySQL error codes, deadlocks, lock wait timeouts, and unique constraint violations.

Members (5)

  • methodIsDeadlock
    public static bool IsDeadlock(Exception? exception)

    Determines whether the specified exception represents a MySQL deadlock (Error 1213).

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the error represents a deadlock; otherwise, `false`.

  • methodIsLockTimeout
    public static bool IsLockTimeout(Exception? exception)

    Determines whether the specified exception represents a MySQL lock wait timeout (Error 1205).

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the error represents a lock wait timeout; otherwise, `false`.

  • methodIsTransient
    public static bool IsTransient(Exception? exception)

    Determines whether the specified exception represents a transient failure suitable for retry.

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the error is transient; otherwise, `false`.

  • methodIsUniqueViolation
    public static bool IsUniqueViolation(Exception? exception)

    Determines whether the specified exception represents a duplicate key violation (Error 1062).

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the error represents a duplicate entry; otherwise, `false`.

  • methodToConcurrencyConflict
    public static ConcurrencyConflict? ToConcurrencyConflict(MySqlException exception, string entityId, string entityType, string? operation = null)

    Translates a `MySqlException` into a structured `ConcurrencyConflict`.

    exception: MySqlException
    The MySQL exception to translate.
    entityId: string
    The unique identifier of the entity involved.
    entityType: string
    The type name of the entity involved.
    operation: string?
    The operation name being executed.

    Returns: A populated `ConcurrencyConflict` if recognized as a concurrency error; otherwise, `null`.

    Exceptions: ArgumentNullException: `exception` is `null`

class

MySqlLockExtensions

Assembly: EricksonLopez.Concurrency.MySql
public static class MySqlLockExtensions

Provides extension methods for appending MySQL locking clauses to query strings.

Members (1)

  • methodWithMySqlLock
    public static string WithMySqlLock(this string sqlQuery, MySqlLockMode lockMode)

    Appends the appropriate MySQL locking clause to the specified SELECT query.

    sqlQuery: this string
    The base SQL select query.
    lockMode: MySqlLockMode
    The MySQL lock mode to append.

    Returns: The modified query with the locking clause attached.

    Exceptions: ArgumentException: `sqlQuery` is `null` or whitespace; ArgumentOutOfRangeException: `lockMode` is not a valid `MySqlLockMode`

enum

MySqlLockMode

Assembly: EricksonLopez.Concurrency.MySql
public enum MySqlLockMode

Specifies MySQL locking clauses for pessimistic record locking.

Members (4)

  • fieldForShare
    ForShare

    Shared read lock (`FOR SHARE`).

  • fieldForUpdate
    ForUpdate

    Exclusive write lock (`FOR UPDATE`).

  • fieldForUpdateNowait
    ForUpdateNowait

    Exclusive write lock failing immediately if locked (`FOR UPDATE NOWAIT`).

  • fieldForUpdateSkipLocked
    ForUpdateSkipLocked

    Exclusive write lock skipping locked records (`FOR UPDATE SKIP LOCKED`).

EricksonLopez.Concurrency.MySql.DependencyInjection#

1
class

MySqlConcurrencyServiceCollectionExtensions

Assembly: EricksonLopez.Concurrency.MySql
public static class MySqlConcurrencyServiceCollectionExtensions

Provides extension methods for registering MySQL concurrency services into an `IServiceCollection`.

Members (1)

  • methodAddEricksonLopezConcurrencyMySql
    public static IServiceCollection AddEricksonLopezConcurrencyMySql(this IServiceCollection services)

    Registers MySQL concurrency dialect services into the dependency injection container.

    services: this IServiceCollection
    The `IServiceCollection` to add services to.

    Returns: The `IServiceCollection` instance so that additional calls can be chained.

    Exceptions: ArgumentNullException: `services` is `null`

EricksonLopez.Concurrency.Oracle#

4
class

OracleConcurrencyErrorClassifier

Assembly: EricksonLopez.Concurrency.Oracle
public static class OracleConcurrencyErrorClassifier

Classifies Oracle error codes, deadlocks, serialization conflicts, and resource busy conditions.

Members (6)

  • methodIsDeadlock
    public static bool IsDeadlock(Exception? exception)

    Determines whether the specified exception represents an Oracle deadlock (ORA-00060).

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the error represents a deadlock; otherwise, `false`.

  • methodIsResourceBusy
    public static bool IsResourceBusy(Exception? exception)

    Determines whether the specified exception represents an Oracle resource busy condition (ORA-00054).

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the resource is busy; otherwise, `false`.

  • methodIsSerializationFailure
    public static bool IsSerializationFailure(Exception? exception)

    Determines whether the specified exception represents an Oracle serialization failure (ORA-08177).

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the error represents a serialization failure; otherwise, `false`.

  • methodIsTransient
    public static bool IsTransient(Exception? exception)

    Determines whether the specified exception represents a transient failure suitable for retry.

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the error is transient; otherwise, `false`.

  • methodIsUniqueViolation
    public static bool IsUniqueViolation(Exception? exception)

    Determines whether the specified exception represents an Oracle unique constraint violation (ORA-00001).

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the error represents a unique constraint violation; otherwise, `false`.

  • methodToConcurrencyConflict
    public static ConcurrencyConflict? ToConcurrencyConflict(OracleException exception, string entityId, string entityType, string? operation = null)

    Translates an `OracleException` into a structured `ConcurrencyConflict`.

    exception: OracleException
    The Oracle exception to translate.
    entityId: string
    The unique identifier of the entity involved.
    entityType: string
    The type name of the entity involved.
    operation: string?
    The operation name being executed.

    Returns: A populated `ConcurrencyConflict` if recognized as a concurrency error; otherwise, `null`.

    Exceptions: ArgumentNullException: `exception` is `null`

class

OracleLockExtensions

Assembly: EricksonLopez.Concurrency.Oracle
public static class OracleLockExtensions

Provides extension methods for appending Oracle locking clauses to query strings.

Members (2)

  • methodWithOracleLock
    public static string WithOracleLock(this string sqlQuery, OracleLockMode lockMode)

    Appends the appropriate Oracle locking clause to the specified SELECT query.

    sqlQuery: this string
    The base SQL select query.
    lockMode: OracleLockMode
    The Oracle lock mode to append.

    Returns: The modified query with the locking clause attached.

    Exceptions: ArgumentException: `sqlQuery` is `null` or whitespace; ArgumentOutOfRangeException: `lockMode` is not a valid `OracleLockMode`

  • methodWithOracleLockWait
    public static string WithOracleLockWait(this string sqlQuery, int timeoutSeconds)

    Appends a `FOR UPDATE WAIT [seconds]` clause to the specified SELECT query.

    sqlQuery: this string
    The base SQL select query.
    timeoutSeconds: int
    The lock wait timeout in seconds.

    Returns: The modified query with the timed lock clause attached.

    Exceptions: ArgumentException: `sqlQuery` is `null` or whitespace; ArgumentOutOfRangeException: `timeoutSeconds` is negative

enum

OracleLockMode

Assembly: EricksonLopez.Concurrency.Oracle
public enum OracleLockMode

Specifies Oracle locking clauses for pessimistic record locking.

Members (3)

  • fieldForUpdate
    ForUpdate

    Exclusive write lock (`FOR UPDATE`).

  • fieldForUpdateNowait
    ForUpdateNowait

    Exclusive write lock failing immediately if locked (`FOR UPDATE NOWAIT`).

  • fieldForUpdateSkipLocked
    ForUpdateSkipLocked

    Exclusive write lock skipping locked records (`FOR UPDATE SKIP LOCKED`).

record

OracleRowScnToken

Assembly: EricksonLopez.Concurrency.Oracle
public readonly record struct OracleRowScnToken : IConcurrencyToken, IComparable<OracleRowScnToken>, IComparable
Implements: IComparable, IComparable<OracleRowScnToken>, IConcurrencyToken

Represents an immutable concurrency token wrapping the Oracle pseudo-column `ORA_ROWSCN` (System Change Number).

Members (15)

  • constructorOracleRowScnToken
    public OracleRowScnToken(long rowScn)

    Initializes a new instance of the `OracleRowScnToken` struct with the specified SCN.

    rowScn: long
    The non-negative Oracle SCN value.

    Exceptions: ArgumentOutOfRangeException: `rowScn` is negative

  • methodCompareTo
    public int CompareTo(OracleRowScnToken other)

    Inherits documentation from base type or interface.

    other: OracleRowScnToken
  • methodCompareTo
    public int CompareTo(object? obj)

    Inherits documentation from base type or interface.

    obj: object?

    Exceptions: ArgumentException: `obj` is not an instance of `OracleRowScnToken`

  • methodEquals
    public bool Equals(IConcurrencyToken? other)

    Inherits documentation from base type or interface.

    other: IConcurrencyToken?
  • methodParse
    public static OracleRowScnToken Parse(string scnString)

    Parses a string representation of an Oracle SCN into an `OracleRowScnToken`.

    scnString: string
    The string representation of the SCN.

    Returns: A new `OracleRowScnToken` instance.

    Exceptions: ArgumentException: `scnString` is `null` or whitespace; FormatException: `scnString` is not in a valid numeric format

  • methodToString
    public override string ToString()

    Inherits documentation from base type or interface.

  • methodoperator <
    public static bool operator <(OracleRowScnToken left, OracleRowScnToken right)

    Determines whether the left token is less than the right token.

    left: OracleRowScnToken
    The left token to compare.
    right: OracleRowScnToken
    The right token to compare.

    Returns: `true` if `left` is less than `right`; otherwise, `false`.

  • methodoperator <=
    public static bool operator <=(OracleRowScnToken left, OracleRowScnToken right)

    Determines whether the left token is less than or equal to the right token.

    left: OracleRowScnToken
    The left token to compare.
    right: OracleRowScnToken
    The right token to compare.

    Returns: `true` if `left` is less than or equal to `right`; otherwise, `false`.

  • methodoperator >
    public static bool operator >(OracleRowScnToken left, OracleRowScnToken right)

    Determines whether the left token is greater than the right token.

    left: OracleRowScnToken
    The left token to compare.
    right: OracleRowScnToken
    The right token to compare.

    Returns: `true` if `left` is greater than `right`; otherwise, `false`.

  • methodoperator >=
    public static bool operator >=(OracleRowScnToken left, OracleRowScnToken right)

    Determines whether the left token is greater than or equal to the right token.

    left: OracleRowScnToken
    The left token to compare.
    right: OracleRowScnToken
    The right token to compare.

    Returns: `true` if `left` is greater than or equal to `right`; otherwise, `false`.

  • propertyIsEmpty
    public bool IsEmpty { get; }

    Gets a value indicating whether the token represents an empty or uninitialized state.

  • propertyRowScn
    public long RowScn { get; }

    Gets the underlying 64-bit System Change Number.

  • propertyTokenKind
    public string TokenKind { get; }

    Gets an opaque discriminator or type tag representing the token format (e.g., "RowVersion", "ETag", "Xmin", "Hash").

  • propertyValue
    public string Value { get; }

    Gets the raw string representation of the concurrency token.

  • fieldNone
    public static readonly OracleRowScnToken None

    Represents an uninitialized or empty Oracle SCN token.

EricksonLopez.Concurrency.Oracle.DependencyInjection#

1
class

OracleConcurrencyServiceCollectionExtensions

Assembly: EricksonLopez.Concurrency.Oracle
public static class OracleConcurrencyServiceCollectionExtensions

Provides extension methods for registering Oracle concurrency services into an `IServiceCollection`.

Members (1)

  • methodAddEricksonLopezConcurrencyOracle
    public static IServiceCollection AddEricksonLopezConcurrencyOracle(this IServiceCollection services)

    Registers Oracle concurrency dialect services into the dependency injection container.

    services: this IServiceCollection
    The `IServiceCollection` to add services to.

    Returns: The `IServiceCollection` instance so that additional calls can be chained.

    Exceptions: ArgumentNullException: `services` is `null`

EricksonLopez.Concurrency.PostgreSql#

5
class

PostgreSqlConcurrencyErrorClassifier

Assembly: EricksonLopez.Concurrency.PostgreSql
public static class PostgreSqlConcurrencyErrorClassifier

Classifies PostgreSQL-specific error codes and exceptions into structured concurrency conflict models and resilience categories.

Members (11)

  • methodIsDeadlock
    public static bool IsDeadlock(Exception? exception)

    Determines whether the specified exception represents a detected PostgreSQL deadlock (SQLSTATE 40P01).

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the exception represents a deadlock; otherwise, `false`.

  • methodIsLockNotAvailable
    public static bool IsLockNotAvailable(Exception? exception)

    Determines whether the specified exception represents a PostgreSQL lock acquisition failure (SQLSTATE 55P03).

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the exception represents an unavailable lock; otherwise, `false`.

  • methodIsSerializationFailure
    public static bool IsSerializationFailure(Exception? exception)

    Determines whether the specified exception represents a PostgreSQL transaction serialization conflict (SQLSTATE 40001).

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the exception represents a serialization failure; otherwise, `false`.

  • methodIsTransient
    public static bool IsTransient(Exception? exception)

    Determines whether the specified exception represents a transient PostgreSQL failure suitable for transaction retry.

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the exception is transient; otherwise, `false`.

  • methodIsUniqueViolation
    public static bool IsUniqueViolation(Exception? exception)

    Determines whether the specified exception represents a PostgreSQL unique constraint violation (SQLSTATE 23505).

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the exception represents a unique constraint violation; otherwise, `false`.

  • methodToConcurrencyConflict
    public static ConcurrencyConflict? ToConcurrencyConflict(Exception exception, string entityId, string entityType, string operation = "")

    Translates recognized PostgreSQL concurrency exceptions into a structured `ConcurrencyConflict`.

    exception: Exception
    The exception caught during database operations.
    entityId: string
    The unique identifier of the target entity.
    entityType: string
    The type name of the target entity.
    operation: string
    The name of the operation being executed.

    Returns: A populated `ConcurrencyConflict` if recognized as a concurrency failure; otherwise, `null`.

    Exceptions: ArgumentNullException: `exception` is `null`

  • fieldDeadlockDetectedSqlState
    public const string DeadlockDetectedSqlState

    Specifies PostgreSQL SQLSTATE 40P01 (deadlock_detected between concurrent database transactions).

  • fieldInFailedSqlTransactionSqlState
    public const string InFailedSqlTransactionSqlState

    Specifies PostgreSQL SQLSTATE 25P02 (in_failed_sql_transaction).

  • fieldLockNotAvailableSqlState
    public const string LockNotAvailableSqlState

    Specifies PostgreSQL SQLSTATE 55P03 (lock_not_available when lock acquisition cannot be fulfilled immediately).

  • fieldSerializationFailureSqlState
    public const string SerializationFailureSqlState

    Specifies PostgreSQL SQLSTATE 40001 (serialization_failure under SERIALIZABLE or REPEATABLE READ isolation).

  • fieldUniqueViolationSqlState
    public const string UniqueViolationSqlState

    Specifies PostgreSQL SQLSTATE 23505 (unique_violation due to primary key or unique index collision).

class

PostgreSqlLockExtensions

Assembly: EricksonLopez.Concurrency.PostgreSql
public static class PostgreSqlLockExtensions

Provides extension methods for constructing PostgreSQL row-level locking SQL clauses.

Members (2)

  • methodToSqlClause
    public static string ToSqlClause(this PostgreSqlLockMode mode)

    Converts a `PostgreSqlLockMode` to its corresponding SQL locking clause.

    mode: this PostgreSqlLockMode
    The PostgreSQL lock mode to convert.

    Returns: The raw SQL locking clause string.

    Exceptions: ArgumentOutOfRangeException: `mode` is not a valid `PostgreSqlLockMode`

  • methodWithLock
    public static string WithLock(this string selectSql, PostgreSqlLockMode mode)

    Appends a PostgreSQL row-level locking clause to the specified SELECT statement.

    selectSql: this string
    The base SELECT statement.
    mode: PostgreSqlLockMode
    The lock mode to append.

    Returns: The modified SQL query with the lock clause appended.

    Exceptions: ArgumentException: `selectSql` is `null` or whitespace

enum

PostgreSqlLockMode

Assembly: EricksonLopez.Concurrency.PostgreSql
public enum PostgreSqlLockMode : byte

Specifies PostgreSQL row-level locking modes used in pessimistic queries.

Members (5)

  • fieldForNoKeyUpdate
    ForNoKeyUpdate = 4

    Locks selected rows without blocking non-key updates (`FOR NO KEY UPDATE`).

  • fieldForShare
    ForShare = 3

    Locks selected rows with shared read lock (`FOR SHARE`).

  • fieldForUpdate
    ForUpdate = 0

    Locks selected rows with exclusive write lock (`FOR UPDATE`).

  • fieldForUpdateNoWait
    ForUpdateNoWait = 1

    Attempts to lock selected rows with exclusive write lock without waiting (`FOR UPDATE NOWAIT`).

  • fieldForUpdateSkipLocked
    ForUpdateSkipLocked = 2

    Locks available selected rows, skipping any rows currently locked by concurrent transactions (`FOR UPDATE SKIP LOCKED`).

class

RowVersionTypeHandler

Assembly: EricksonLopez.Concurrency.PostgreSql
public static class RowVersionTypeHandler

Provides overflow-checked ADO.NET parameter binding and reader hydration for PostgreSQL 32-bit unsigned optimistic concurrency tokens (`uint` `RowVersion` / `XminConcurrencyToken`) mapped to `BIGINT` (`DbType.Int64`) or `xid`, avoiding Npgsql's rejection of `DbType.UInt32`.

Members (4)

  • methodParseUInt32
    public static uint ParseUInt32(object value)

    Parses a PostgreSQL scalar value (`uint`, `long`, `int`, `short`, or numeric string) into an overflow-checked `uint`.

    value: object
    The raw database column value.

    Returns: The validated 32-bit unsigned row version.

    Exceptions: OverflowException: `value` is negative or exceeds `uint.MaxValue`.

  • methodParseXminToken
    public static XminConcurrencyToken ParseXminToken(object value)

    Parses a PostgreSQL scalar value into an `XminConcurrencyToken`.

    value: object
    The raw database column value.

    Returns: The hydrated `XminConcurrencyToken`.

  • methodSetParameterValue
    public static void SetParameterValue(IDbDataParameter parameter, uint value)

    Binds a 32-bit unsigned optimistic concurrency version onto `parameter` as `DbType.Int64`.

    parameter: IDbDataParameter
    The target ADO.NET parameter.
    value: uint
    The unsigned 32-bit row version.
  • methodSetParameterValue
    public static void SetParameterValue(IDbDataParameter parameter, XminConcurrencyToken token)

    Binds an `XminConcurrencyToken` onto `parameter` as `DbType.Int64`.

    parameter: IDbDataParameter
    The target ADO.NET parameter.
    token: XminConcurrencyToken
    The PostgreSQL xmin concurrency token.
record

XminConcurrencyToken

Assembly: EricksonLopez.Concurrency.PostgreSql
public readonly record struct XminConcurrencyToken : IConcurrencyToken, IComparable<XminConcurrencyToken>, IComparable, ISpanFormattable
Implements: IComparable, IComparable<XminConcurrencyToken>, IConcurrencyToken, ISpanFormattable

Represents an immutable concurrency token wrapping the native PostgreSQL system column `xmin` (32-bit transaction ID).

Members (20)

  • constructorXminConcurrencyToken
    public XminConcurrencyToken(uint xmin)

    Initializes a new instance of the `XminConcurrencyToken` struct with the specified transaction ID.

    xmin: uint
    The 32-bit unsigned transaction ID from PostgreSQL.
  • methodCompareTo
    public int CompareTo(object? obj)

    Inherits documentation from base type or interface.

    obj: object?

    Exceptions: ArgumentException: `obj` is not an instance of `XminConcurrencyToken`

  • methodCompareTo
    public int CompareTo(XminConcurrencyToken other)

    Inherits documentation from base type or interface.

    other: XminConcurrencyToken
  • methodEquals
    public bool Equals(IConcurrencyToken? other)

    Inherits documentation from base type or interface.

    other: IConcurrencyToken?
  • methodFrom
    public static XminConcurrencyToken From(uint xmin)

    Creates a new `XminConcurrencyToken` from a 32-bit unsigned integer.

    xmin: uint
    The 32-bit unsigned transaction ID.

    Returns: A new `XminConcurrencyToken` instance.

  • methodParse
    public static XminConcurrencyToken Parse(string value)

    Parses an xmin value from its string representation.

    value: string
    The string representation of the unsigned 32-bit integer.

    Returns: A new `XminConcurrencyToken` instance.

    Exceptions: ArgumentException: `value` is `null` or whitespace; FormatException: `value` is not in a valid numeric format

  • methodToString
    public override string ToString()

    Inherits documentation from base type or interface.

  • methodToString
    public string ToString(string? format, IFormatProvider? formatProvider)

    Inherits documentation from base type or interface.

    format: string?
    formatProvider: IFormatProvider?
  • methodTryFormat
    public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)

    Inherits documentation from base type or interface.

    destination: Span<char>
    charsWritten: out int
    format: ReadOnlySpan<char>
    provider: IFormatProvider?
  • methodimplicit operator XminConcurrencyToken
    public static implicit operator XminConcurrencyToken(uint xmin)

    Converts a 32-bit unsigned integer to an `XminConcurrencyToken`.

    xmin: uint
    The transaction ID value to convert.

    Returns: A new `XminConcurrencyToken` instance wrapping the specified transaction ID.

  • methodimplicit operator uint
    public static implicit operator uint(XminConcurrencyToken token)

    Converts an `XminConcurrencyToken` to a 32-bit unsigned integer.

    token: XminConcurrencyToken
    The token instance to convert.

    Returns: The underlying 32-bit unsigned transaction ID value.

  • methodoperator <
    public static bool operator <(XminConcurrencyToken left, XminConcurrencyToken right)

    Determines whether the left token is less than the right token.

    left: XminConcurrencyToken
    The left token to compare.
    right: XminConcurrencyToken
    The right token to compare.

    Returns: `true` if `left` is less than `right`; otherwise, `false`.

  • methodoperator <=
    public static bool operator <=(XminConcurrencyToken left, XminConcurrencyToken right)

    Determines whether the left token is less than or equal to the right token.

    left: XminConcurrencyToken
    The left token to compare.
    right: XminConcurrencyToken
    The right token to compare.

    Returns: `true` if `left` is less than or equal to `right`; otherwise, `false`.

  • methodoperator >
    public static bool operator >(XminConcurrencyToken left, XminConcurrencyToken right)

    Determines whether the left token is greater than the right token.

    left: XminConcurrencyToken
    The left token to compare.
    right: XminConcurrencyToken
    The right token to compare.

    Returns: `true` if `left` is greater than `right`; otherwise, `false`.

  • methodoperator >=
    public static bool operator >=(XminConcurrencyToken left, XminConcurrencyToken right)

    Determines whether the left token is greater than or equal to the right token.

    left: XminConcurrencyToken
    The left token to compare.
    right: XminConcurrencyToken
    The right token to compare.

    Returns: `true` if `left` is greater than or equal to `right`; otherwise, `false`.

  • propertyIsEmpty
    public bool IsEmpty { get; }

    Gets a value indicating whether the token represents an empty or uninitialized state.

  • propertyTokenKind
    public string TokenKind { get; }

    Gets an opaque discriminator or type tag representing the token format (e.g., "RowVersion", "ETag", "Xmin", "Hash").

  • propertyValue
    public string Value { get; }

    Gets the raw string representation of the concurrency token.

  • propertyXmin
    public uint Xmin { get; }

    Gets the underlying 32-bit PostgreSQL transaction ID.

  • fieldNone
    public static readonly XminConcurrencyToken None

    Represents an uninitialized or empty xmin token (0).

EricksonLopez.Concurrency.PostgreSql.DependencyInjection#

1
class

PostgreSqlConcurrencyServiceCollectionExtensions

Assembly: EricksonLopez.Concurrency.PostgreSql
public static class PostgreSqlConcurrencyServiceCollectionExtensions

Provides extension methods for registering PostgreSQL concurrency services into an `IServiceCollection`.

Members (1)

  • methodAddEricksonLopezConcurrencyPostgreSql
    public static IServiceCollection AddEricksonLopezConcurrencyPostgreSql(this IServiceCollection services)

    Registers PostgreSQL concurrency adapter services and diagnostic classifiers.

    services: this IServiceCollection
    The `IServiceCollection` to add services to.

    Returns: The `IServiceCollection` instance so that additional calls can be chained.

    Exceptions: ArgumentNullException: `services` is `null`

EricksonLopez.Concurrency.Resolvers#

4
class

DelegateConflictResolver<TEntity>

Assembly: EricksonLopez.Concurrency
public sealed class DelegateConflictResolver<TEntity> : IConcurrencyConflictResolver<TEntity> where TEntity : class
Implements: IConcurrencyConflictResolver<TEntity>

Resolves optimistic concurrency conflicts by executing a custom reconciliation delegate.

Remarks:

Type parameters: TEntity: The type of the domain entity or aggregate root.

Members (2)

  • constructorDelegateConflictResolver
    public DelegateConflictResolver(Func<TEntity, TEntity?, ConcurrencyConflict, CancellationToken, ValueTask<ConflictResolution<TEntity>>> resolveDelegate)

    Initializes a new instance of the `DelegateConflictResolver<TEntity>` class with the specified reconciliation delegate.

    resolveDelegate: Func<TEntity, TEntity?, ConcurrencyConflict, CancellationToken, ValueTask<ConflictResolution<TEntity>>>
    The custom asynchronous delegate used to reconcile conflicting entity states.

    Exceptions: ArgumentNullException: `resolveDelegate` is `null`

  • methodResolveAsync
    public async ValueTask<ConflictResolution<TEntity>> ResolveAsync(TEntity proposedEntity, TEntity? currentDatabaseEntity, ConcurrencyConflict conflict, CancellationToken cancellationToken = default)

    Attempts to resolve a detected concurrency conflict between the proposed local entity state and the latest persistent state.

    proposedEntity: TEntity
    The local modified entity state that provoked the conflict.
    currentDatabaseEntity: TEntity?
    The current persistent entity state retrieved from storage, or `null` if deleted or missing.
    conflict: ConcurrencyConflict
    The conflict descriptor containing diagnostic and contextual metadata.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Returns: A value task representing the asynchronous operation. The task result contains the `ConflictResolution<TEntity>` outcome.

class

LastWriteWinsConflictResolver<TEntity>

Assembly: EricksonLopez.Concurrency
public sealed class LastWriteWinsConflictResolver<TEntity> : IConcurrencyConflictResolver<TEntity> where TEntity : class
Implements: IConcurrencyConflictResolver<TEntity>

Resolves optimistic concurrency conflicts by explicitly overwriting storage with the local proposed state.

Remarks:

Use this resolver with caution as it unconditionally overwrites concurrent modifications without domain inspection. Type parameters: TEntity: The type of the domain entity or aggregate root.

Members (2)

  • methodResolveAsync
    public ValueTask<ConflictResolution<TEntity>> ResolveAsync(TEntity proposedEntity, TEntity? currentDatabaseEntity, ConcurrencyConflict conflict, CancellationToken cancellationToken = default)

    Attempts to resolve a detected concurrency conflict between the proposed local entity state and the latest persistent state.

    proposedEntity: TEntity
    The local modified entity state that provoked the conflict.
    currentDatabaseEntity: TEntity?
    The current persistent entity state retrieved from storage, or `null` if deleted or missing.
    conflict: ConcurrencyConflict
    The conflict descriptor containing diagnostic and contextual metadata.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Returns: A value task representing the asynchronous operation. The task result contains the `ConflictResolution<TEntity>` outcome.

  • fieldInstance
    public static readonly LastWriteWinsConflictResolver<TEntity> Instance

    Gets the shared singleton instance of `LastWriteWinsConflictResolver<TEntity>`.

class

RefreshAndRetryConflictResolver<TEntity>

Assembly: EricksonLopez.Concurrency
public sealed class RefreshAndRetryConflictResolver<TEntity> : IConcurrencyConflictResolver<TEntity> where TEntity : class
Implements: IConcurrencyConflictResolver<TEntity>

Resolves optimistic concurrency conflicts by reloading the latest state from persistent storage and re-applying mutations.

Remarks:

Type parameters: TEntity: The type of the domain entity or aggregate root.

Members (5)

  • constructorRefreshAndRetryConflictResolver
    public RefreshAndRetryConflictResolver(Func<string, CancellationToken, ValueTask<TEntity?>> refreshDelegate, Func<TEntity, TEntity, TEntity> reapplyDelegate, int maxRetries = 3, Func<int, TimeSpan>? retryDelayProvider = null)

    Initializes a new instance of the `RefreshAndRetryConflictResolver<TEntity>` class with refresh and reapply delegates.

    refreshDelegate: Func<string, CancellationToken, ValueTask<TEntity?>>
    An asynchronous delegate that retrieves the latest persistent state for a given entity identifier.
    reapplyDelegate: Func<TEntity, TEntity, TEntity>
    A delegate that re-applies local changes onto the freshly reloaded state.
    maxRetries: int
    The maximum number of reload attempts permitted. Must be at least 1.
    retryDelayProvider: Func<int, TimeSpan>?
    An optional delegate supplying a backoff delay based on the current retry attempt (1-based).

    Exceptions: ArgumentNullException: `refreshDelegate` or `reapplyDelegate` is `null`; ArgumentOutOfRangeException: `maxRetries` is less than 1

  • constructorRefreshAndRetryConflictResolver
    public RefreshAndRetryConflictResolver(Func<string, CancellationToken, ValueTask<TEntity?>> refreshDelegate, int maxRetries = 3, Func<int, TimeSpan>? retryDelayProvider = null)

    Initializes a new instance of the `RefreshAndRetryConflictResolver<TEntity>` class with the specified refresh delegate.

    refreshDelegate: Func<string, CancellationToken, ValueTask<TEntity?>>
    An asynchronous delegate that retrieves the latest persistent state for a given entity identifier.
    maxRetries: int
    The maximum number of reload attempts permitted. Must be at least 1.
    retryDelayProvider: Func<int, TimeSpan>?
    An optional delegate supplying a backoff delay based on the current retry attempt (1-based).

    Exceptions: ArgumentNullException: `refreshDelegate` is `null`; ArgumentOutOfRangeException: `maxRetries` is less than 1

  • methodResolveAsync
    public async ValueTask<ConflictResolution<TEntity>> ResolveAsync(TEntity proposedEntity, TEntity? currentDatabaseEntity, ConcurrencyConflict conflict, CancellationToken cancellationToken = default)

    Attempts to resolve a detected concurrency conflict between the proposed local entity state and the latest persistent state.

    proposedEntity: TEntity
    The local modified entity state that provoked the conflict.
    currentDatabaseEntity: TEntity?
    The current persistent entity state retrieved from storage, or `null` if deleted or missing.
    conflict: ConcurrencyConflict
    The conflict descriptor containing diagnostic and contextual metadata.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Returns: A value task representing the asynchronous operation. The task result contains the `ConflictResolution<TEntity>` outcome.

  • propertyMaxRetries
    public int MaxRetries { get; }

    Gets the maximum number of retry reload attempts permitted.

  • propertyRetryDelayProvider
    public Func<int, TimeSpan>? RetryDelayProvider { get; }

    Gets the optional retry delay/backoff provider function.

class

RejectConflictResolver<TEntity>

Assembly: EricksonLopez.Concurrency
public sealed class RejectConflictResolver<TEntity> : IConcurrencyConflictResolver<TEntity> where TEntity : class
Implements: IConcurrencyConflictResolver<TEntity>

Resolves optimistic concurrency conflicts by strictly rejecting all conflicts.

Remarks:

Type parameters: TEntity: The type of the domain entity or aggregate root.

Members (2)

  • methodResolveAsync
    public ValueTask<ConflictResolution<TEntity>> ResolveAsync(TEntity proposedEntity, TEntity? currentDatabaseEntity, ConcurrencyConflict conflict, CancellationToken cancellationToken = default)

    Attempts to resolve a detected concurrency conflict between the proposed local entity state and the latest persistent state.

    proposedEntity: TEntity
    The local modified entity state that provoked the conflict.
    currentDatabaseEntity: TEntity?
    The current persistent entity state retrieved from storage, or `null` if deleted or missing.
    conflict: ConcurrencyConflict
    The conflict descriptor containing diagnostic and contextual metadata.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Returns: A value task representing the asynchronous operation. The task result contains the `ConflictResolution<TEntity>` outcome.

  • fieldInstance
    public static readonly RejectConflictResolver<TEntity> Instance

    Gets the shared singleton instance of `RejectConflictResolver<TEntity>`.

EricksonLopez.Concurrency.Result#

2
class

ConcurrencyErrors

Assembly: EricksonLopez.Concurrency.Result
public static class ConcurrencyErrors

Provides factory methods to create structured `Error` instances representing optimistic concurrency conflicts.

Members (9)

  • methodFromConflict
    public static Error FromConflict(ConcurrencyConflict conflict)

    Converts a `ConcurrencyConflict` into a structured `Error` with metadata and retryability classification.

    conflict: ConcurrencyConflict
    The rich conflict descriptor containing failure diagnostics.

    Returns: A structured `Error` configured with `ErrorType.Conflict`.

    Exceptions: ArgumentNullException: `conflict` is `null`

  • methodTokenMismatch
    public static Error TokenMismatch(string entityId, string entityType, IConcurrencyToken expected, IConcurrencyToken? actual = null)

    Creates a structured `Error` representing an optimistic token mismatch.

    entityId: string
    The unique identifier of the entity involved in the conflict.
    entityType: string
    The type name of the entity involved in the conflict.
    expected: IConcurrencyToken
    The expected concurrency token constraint.
    actual: IConcurrencyToken?
    The actual concurrency token discovered in storage, if known.

    Returns: A structured conflict `Error`.

  • methodVersionMismatch
    public static Error VersionMismatch(string entityId, string entityType, ExpectedVersion expected, ActualVersion? actual = null)

    Creates a structured `Error` representing an optimistic version mismatch.

    entityId: string
    The unique identifier of the entity involved in the conflict.
    entityType: string
    The type name of the entity involved in the conflict.
    expected: ExpectedVersion
    The expected version constraint.
    actual: ActualVersion?
    The actual version discovered in storage, if known.

    Returns: A structured conflict `Error`.

  • fieldConcurrencyConflictCode
    public const string ConcurrencyConflictCode

    Specifies the default machine-readable error code for general optimistic concurrency conflicts.

  • fieldDeadlockCode
    public const string DeadlockCode

    Specifies the machine-readable error code for database deadlock conditions.

  • fieldEntityDeletedCode
    public const string EntityDeletedCode

    Specifies the machine-readable error code when an entity is missing or deleted.

  • fieldSerializationFailureCode
    public const string SerializationFailureCode

    Specifies the machine-readable error code for database serialization failures.

  • fieldTokenMismatchCode
    public const string TokenMismatchCode

    Specifies the machine-readable error code for optimistic token mismatches.

  • fieldVersionMismatchCode
    public const string VersionMismatchCode

    Specifies the machine-readable error code for optimistic version mismatches.

class

ConcurrencyResultExtensions

Assembly: EricksonLopez.Concurrency.Result
public static class ConcurrencyResultExtensions

Provides extension methods converting concurrency outcomes, CAS results, and row counts into functional `ResultInstance` and `Result<TValue>`.

Members (5)

  • methodFromRowsAffected
    public static ResultInstance FromRowsAffected(int rowsAffected, string entityId, string entityType, ExpectedVersion expectedVersion)

    Evaluates the number of rows affected by an optimistic UPDATE command and returns a `ResultInstance`.

    rowsAffected: int
    The number of rows modified by the database command.
    entityId: string
    The unique identifier of the target entity.
    entityType: string
    The type name of the target entity.
    expectedVersion: ExpectedVersion
    The expected version constraint used in the query.

    Returns: A successful `ResultInstance` if `rowsAffected` is greater than zero; otherwise, a structured conflict failure.

  • methodFromRowsAffected<TEntity>
    public static Result<TEntity> FromRowsAffected<TEntity>(int rowsAffected, TEntity entity, string entityId, ExpectedVersion expectedVersion) where TEntity : class

    Evaluates the number of rows affected by an optimistic UPDATE command and returns the entity in a `Result<TValue>`.

    rowsAffected: int
    The number of rows modified by the database command.
    entity: TEntity
    The entity instance to return upon success.
    entityId: string
    The unique identifier of the target entity.
    expectedVersion: ExpectedVersion
    The expected version constraint used in the query.

    Returns: A successful result containing the entity if `rowsAffected` is greater than zero; otherwise, a structured conflict failure.

    Type parameters: TEntity: The type of the target entity. Exceptions: ArgumentNullException: `entity` is `null`

  • methodToResult
    public static ResultInstance ToResult(this ConcurrencyConflict? conflict)

    Converts an optional `ConcurrencyConflict` into a non-generic `ResultInstance`.

    conflict: this ConcurrencyConflict?
    The conflict descriptor to convert, or `null` if the operation was successful.

    Returns: A successful `ResultInstance` if `conflict` is `null`; otherwise, a conflict failure containing the structured error.

  • methodToResult<TEntity>
    public static Result<TEntity> ToResult<TEntity>(this CasResult<TEntity> casResult) where TEntity : class

    Converts a `CasResult<TEntity>` into a functional `Result<TValue>`.

    casResult: this CasResult<TEntity>
    The Compare-And-Swap execution outcome to convert.

    Returns: A successful result containing the mutated entity if the operation succeeded; otherwise, a conflict failure containing the structured error.

    Type parameters: TEntity: The type of the target entity.

  • methodToResult<TEntity>
    public static Result<TEntity> ToResult<TEntity>(this ConflictResolution<TEntity> resolution) where TEntity : class

    Converts a `ConflictResolution<TEntity>` into a functional `Result<TValue>`.

    resolution: this ConflictResolution<TEntity>
    The conflict resolution outcome to convert.

    Returns: A successful result containing the resolved entity if reconciled; otherwise, a conflict failure.

    Type parameters: TEntity: The type of the target entity.

EricksonLopez.Concurrency.SqlServer#

4
class

SqlServerErrorClassifier

Assembly: EricksonLopez.Concurrency.SqlServer
public static class SqlServerErrorClassifier

Classifies Microsoft SQL Server error codes, deadlocks, and snapshot isolation serialization conflicts.

Members (6)

  • methodIsDeadlock
    public static bool IsDeadlock(Exception? exception)

    Determines whether the specified exception represents a SQL Server deadlock (Error 1205).

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the error represents a deadlock; otherwise, `false`.

  • methodIsLockTimeout
    public static bool IsLockTimeout(Exception? exception)

    Determines whether the specified exception represents a SQL Server lock request timeout (Error 1222).

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the lock request timed out; otherwise, `false`.

  • methodIsSerializationFailure
    public static bool IsSerializationFailure(Exception? exception)

    Determines whether the specified exception represents a snapshot isolation update conflict (Error 3960 or 3961).

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the error represents a serialization conflict; otherwise, `false`.

  • methodIsTransient
    public static bool IsTransient(Exception? exception)

    Determines whether the specified exception represents a transient failure suitable for retry.

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the error is transient; otherwise, `false`.

  • methodIsUniqueViolation
    public static bool IsUniqueViolation(Exception? exception)

    Determines whether the specified exception represents a unique constraint or primary key violation (Error 2601 or 2627).

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the error represents a unique violation; otherwise, `false`.

  • methodToConcurrencyConflict
    public static ConcurrencyConflict? ToConcurrencyConflict(SqlException exception, string entityId, string entityType, string? operation = null)

    Translates a `SqlException` into a structured `ConcurrencyConflict`.

    exception: SqlException
    The SQL Server exception to translate.
    entityId: string
    The unique identifier of the entity involved.
    entityType: string
    The type name of the entity involved.
    operation: string?
    The operation name being executed.

    Returns: A populated `ConcurrencyConflict` if recognized as a concurrency error; otherwise, `null`.

    Exceptions: ArgumentNullException: `exception` is `null`

class

SqlServerLockExtensions

Assembly: EricksonLopez.Concurrency.SqlServer
public static class SqlServerLockExtensions

Provides extension methods for appending SQL Server table hints to SQL query strings.

Members (1)

  • methodWithSqlServerTableHint
    public static string WithSqlServerTableHint(this string tableName, SqlServerLockMode lockMode)

    Appends the appropriate SQL Server table hint clause after table identifiers.

    tableName: this string
    The table name.
    lockMode: SqlServerLockMode
    The SQL Server lock hint mode to apply.

    Returns: The table name decorated with table hints.

    Exceptions: ArgumentException: `tableName` is `null` or whitespace; ArgumentOutOfRangeException: `lockMode` is not a valid `SqlServerLockMode`

enum

SqlServerLockMode

Assembly: EricksonLopez.Concurrency.SqlServer
public enum SqlServerLockMode

Specifies Microsoft SQL Server table hints for pessimistic row locking and synchronization.

Members (5)

  • fieldUpdLockRowLock
    UpdLockRowLock

    Update lock on row level (`WITH (UPDLOCK, ROWLOCK)`).

  • fieldUpdLockRowLockNowait
    UpdLockRowLockNowait

    Update lock on row level with immediate failure if locked (`WITH (UPDLOCK, ROWLOCK, NOWAIT)`).

  • fieldUpdLockRowLockReadPast
    UpdLockRowLockReadPast

    Update lock skipping rows locked by other transactions (`WITH (UPDLOCK, ROWLOCK, READPAST)`).

  • fieldXLockRowLock
    XLockRowLock

    Exclusive lock on row level (`WITH (XLOCK, ROWLOCK)`).

  • fieldXLockRowLockNowait
    XLockRowLockNowait

    Exclusive lock on row level with immediate failure if locked (`WITH (XLOCK, ROWLOCK, NOWAIT)`).

struct

SqlServerRowVersionToken

Assembly: EricksonLopez.Concurrency.SqlServer
public readonly struct SqlServerRowVersionToken : IConcurrencyToken, IEquatable<SqlServerRowVersionToken>, IComparable<SqlServerRowVersionToken>, IComparable
Implements: IComparable, IComparable<SqlServerRowVersionToken>, IConcurrencyToken, IEquatable<SqlServerRowVersionToken>

Represents an immutable concurrency token wrapping a Microsoft SQL Server 8-byte `ROWVERSION` or `TIMESTAMP` binary sequence.

Members (21)

  • constructorSqlServerRowVersionToken
    public SqlServerRowVersionToken(ReadOnlySpan<byte> span)

    Initializes a new instance of the `SqlServerRowVersionToken` struct from a read-only byte span.

    span: ReadOnlySpan<byte>
    The byte span representing the rowversion data.
  • constructorSqlServerRowVersionToken
    public SqlServerRowVersionToken(byte[]? rowVersionBytes)

    Initializes a new instance of the `SqlServerRowVersionToken` struct with the specified byte array.

    rowVersionBytes: byte[]?
    The 8-byte rowversion binary array.
  • methodCompareTo
    public int CompareTo(SqlServerRowVersionToken other)

    Inherits documentation from base type or interface.

    other: SqlServerRowVersionToken
  • methodCompareTo
    public int CompareTo(object? obj)

    Inherits documentation from base type or interface.

    obj: object?

    Exceptions: ArgumentException: `obj` is not an instance of `SqlServerRowVersionToken`

  • methodEquals
    public bool Equals(IConcurrencyToken? other)

    Inherits documentation from base type or interface.

    other: IConcurrencyToken?
  • methodEquals
    public bool Equals(SqlServerRowVersionToken other)

    Determines whether the current instance is equal to another `SqlServerRowVersionToken`.

    other: SqlServerRowVersionToken
    The token to compare with.

    Returns: `true` if both tokens have identical values; otherwise, `false`.

  • methodEquals
    public override bool Equals(object? obj)

    Inherits documentation from base type or interface.

    obj: object?
  • methodGetHashCode
    public override int GetHashCode()

    Inherits documentation from base type or interface.

  • methodParse
    public static SqlServerRowVersionToken Parse(string hexString)

    Parses a hexadecimal string representation into a `SqlServerRowVersionToken`.

    hexString: string
    The hexadecimal string to parse.

    Returns: A new `SqlServerRowVersionToken` instance.

    Exceptions: ArgumentException: `hexString` is `null` or whitespace

  • methodToByteArray
    public byte[] ToByteArray()

    Returns a copy of the underlying rowversion byte array.

    Returns: A copy of the raw bytes.

  • methodToString
    public override string ToString()

    Inherits documentation from base type or interface.

  • methodoperator !=
    public static bool operator !=(SqlServerRowVersionToken left, SqlServerRowVersionToken right)

    Determines whether two `SqlServerRowVersionToken` instances represent different values.

    left: SqlServerRowVersionToken
    The left token to compare.
    right: SqlServerRowVersionToken
    The right token to compare.

    Returns: `true` if both tokens are not equal; otherwise, `false`.

  • methodoperator <
    public static bool operator <(SqlServerRowVersionToken left, SqlServerRowVersionToken right)

    Determines whether the left token is less than the right token.

    left: SqlServerRowVersionToken
    The left token to compare.
    right: SqlServerRowVersionToken
    The right token to compare.

    Returns: `true` if `left` is less than `right`; otherwise, `false`.

  • methodoperator <=
    public static bool operator <=(SqlServerRowVersionToken left, SqlServerRowVersionToken right)

    Determines whether the left token is less than or equal to the right token.

    left: SqlServerRowVersionToken
    The left token to compare.
    right: SqlServerRowVersionToken
    The right token to compare.

    Returns: `true` if `left` is less than or equal to `right`; otherwise, `false`.

  • methodoperator ==
    public static bool operator ==(SqlServerRowVersionToken left, SqlServerRowVersionToken right)

    Determines whether two `SqlServerRowVersionToken` instances represent the same value.

    left: SqlServerRowVersionToken
    The left token to compare.
    right: SqlServerRowVersionToken
    The right token to compare.

    Returns: `true` if both tokens are equal; otherwise, `false`.

  • methodoperator >
    public static bool operator >(SqlServerRowVersionToken left, SqlServerRowVersionToken right)

    Determines whether the left token is greater than the right token.

    left: SqlServerRowVersionToken
    The left token to compare.
    right: SqlServerRowVersionToken
    The right token to compare.

    Returns: `true` if `left` is greater than `right`; otherwise, `false`.

  • methodoperator >=
    public static bool operator >=(SqlServerRowVersionToken left, SqlServerRowVersionToken right)

    Determines whether the left token is greater than or equal to the right token.

    left: SqlServerRowVersionToken
    The left token to compare.
    right: SqlServerRowVersionToken
    The right token to compare.

    Returns: `true` if `left` is greater than or equal to `right`; otherwise, `false`.

  • propertyIsEmpty
    public bool IsEmpty { get; }

    Gets a value indicating whether the token represents an empty or uninitialized state.

  • propertyTokenKind
    public string TokenKind { get; }

    Gets an opaque discriminator or type tag representing the token format (e.g., "RowVersion", "ETag", "Xmin", "Hash").

  • propertyValue
    public string Value { get; }

    Gets the raw string representation of the concurrency token.

  • fieldNone
    public static readonly SqlServerRowVersionToken None

    Represents an empty or uninitialized SQL Server rowversion token.

EricksonLopez.Concurrency.SqlServer.DependencyInjection#

1
class

SqlServerConcurrencyServiceCollectionExtensions

Assembly: EricksonLopez.Concurrency.SqlServer
public static class SqlServerConcurrencyServiceCollectionExtensions

Provides extension methods for registering Microsoft SQL Server concurrency services into an `IServiceCollection`.

Members (1)

  • methodAddEricksonLopezConcurrencySqlServer
    public static IServiceCollection AddEricksonLopezConcurrencySqlServer(this IServiceCollection services)

    Registers Microsoft SQL Server concurrency dialect services and classifiers into the dependency injection container.

    services: this IServiceCollection
    The `IServiceCollection` to add services to.

    Returns: The `IServiceCollection` instance so that additional calls can be chained.

    Exceptions: ArgumentNullException: `services` is `null`

EricksonLopez.Concurrency.Sqlite#

1
class

SqliteConcurrencyErrorClassifier

Assembly: EricksonLopez.Concurrency.Sqlite
public static class SqliteConcurrencyErrorClassifier

Classifies SQLite error codes, database busy conditions, table lock collisions, and constraint violations.

Members (5)

  • methodIsBusy
    public static bool IsBusy(Exception? exception)

    Determines whether the specified exception represents a SQLite busy condition (Error 5).

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the database is busy; otherwise, `false`.

  • methodIsConstraintViolation
    public static bool IsConstraintViolation(Exception? exception)

    Determines whether the specified exception represents a SQLite constraint violation (Error 19).

    exception: Exception?
    The exception to inspect.

    Returns: `true` if a constraint violation occurred; otherwise, `false`.

  • methodIsLocked
    public static bool IsLocked(Exception? exception)

    Determines whether the specified exception represents a SQLite table locked condition (Error 6).

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the table is locked; otherwise, `false`.

  • methodIsTransient
    public static bool IsTransient(Exception? exception)

    Determines whether the specified exception represents a transient failure suitable for retry.

    exception: Exception?
    The exception to inspect.

    Returns: `true` if the error is transient; otherwise, `false`.

  • methodToConcurrencyConflict
    public static ConcurrencyConflict? ToConcurrencyConflict(SqliteException exception, string entityId, string entityType, string? operation = null)

    Translates a `SqliteException` into a structured `ConcurrencyConflict`.

    exception: SqliteException
    The SQLite exception to translate.
    entityId: string
    The unique identifier of the entity involved.
    entityType: string
    The type name of the entity involved.
    operation: string?
    The operation name being executed.

    Returns: A populated `ConcurrencyConflict` if recognized as a concurrency error; otherwise, `null`.

    Exceptions: ArgumentNullException: `exception` is `null`

EricksonLopez.Concurrency.Sqlite.DependencyInjection#

1
class

SqliteConcurrencyServiceCollectionExtensions

Assembly: EricksonLopez.Concurrency.Sqlite
public static class SqliteConcurrencyServiceCollectionExtensions

Provides extension methods for registering SQLite concurrency services into an `IServiceCollection`.

Members (1)

  • methodAddEricksonLopezConcurrencySqlite
    public static IServiceCollection AddEricksonLopezConcurrencySqlite(this IServiceCollection services)

    Registers SQLite concurrency dialect services into the dependency injection container.

    services: this IServiceCollection
    The `IServiceCollection` to add services to.

    Returns: The `IServiceCollection` instance so that additional calls can be chained.

    Exceptions: ArgumentNullException: `services` is `null`

EricksonLopez.Concurrency.Testing#

5
class

ConcurrencyConflictBuilder

Assembly: EricksonLopez.Concurrency.Testing
public sealed class ConcurrencyConflictBuilder

Provides a fluent test builder for constructing `ConcurrencyConflict` instances with custom diagnostics and metadata.

Members (11)

  • methodBuild
    public ConcurrencyConflict Build()

    Builds the configured `ConcurrencyConflict` instance.

    Returns: A new `ConcurrencyConflict` with the configured attributes.

  • methodWithClassification
    public ConcurrencyConflictBuilder WithClassification(ConcurrencyConflictClassification classification)

    Sets the retryability classification.

    classification: ConcurrencyConflictClassification
    The classification severity.

    Returns: This builder instance for method chaining.

  • methodWithConflictType
    public ConcurrencyConflictBuilder WithConflictType(ConcurrencyConflictType conflictType)

    Sets the conflict category discriminator.

    conflictType: ConcurrencyConflictType
    The conflict category.

    Returns: This builder instance for method chaining.

  • methodWithEntityId
    public ConcurrencyConflictBuilder WithEntityId(string entityId)

    Sets the target entity identifier for the conflict.

    entityId: string
    The unique identifier of the entity.

    Returns: This builder instance for method chaining.

    Exceptions: ArgumentNullException: `entityId` is `null`

  • methodWithEntityType
    public ConcurrencyConflictBuilder WithEntityType(string entityType)

    Sets the target entity type name for the conflict.

    entityType: string
    The type name of the entity.

    Returns: This builder instance for method chaining.

    Exceptions: ArgumentNullException: `entityType` is `null`

  • methodWithMessage
    public ConcurrencyConflictBuilder WithMessage(string message)

    Sets the conflict descriptive message.

    message: string
    The human-readable message.

    Returns: This builder instance for method chaining.

    Exceptions: ArgumentNullException: `message` is `null`

  • methodWithMetadata
    public ConcurrencyConflictBuilder WithMetadata(string key, string value)

    Adds a diagnostic metadata entry to the conflict.

    key: string
    The metadata key.
    value: string
    The metadata value.

    Returns: This builder instance for method chaining.

    Exceptions: ArgumentNullException: `value` is `null`

  • methodWithOperation
    public ConcurrencyConflictBuilder WithOperation(string operation)

    Sets the operation name.

    operation: string
    The operation name.

    Returns: This builder instance for method chaining.

    Exceptions: ArgumentNullException: `operation` is `null`

  • methodWithTokens
    public ConcurrencyConflictBuilder WithTokens(IConcurrencyToken expected, IConcurrencyToken actual)

    Sets the expected and actual concurrency tokens.

    expected: IConcurrencyToken
    The expected token.
    actual: IConcurrencyToken
    The actual current token.

    Returns: This builder instance for method chaining.

  • methodWithVersions
    public ConcurrencyConflictBuilder WithVersions(ExpectedVersion expected, ActualVersion actual)

    Sets the expected and actual numeric version constraints.

    expected: ExpectedVersion
    The expected version.
    actual: ActualVersion
    The actual current version.

    Returns: This builder instance for method chaining.

  • methodimplicit operator ConcurrencyConflict
    public static implicit operator ConcurrencyConflict(ConcurrencyConflictBuilder builder)

    Converts a `ConcurrencyConflictBuilder` to a `ConcurrencyConflict`.

    builder: ConcurrencyConflictBuilder
    The builder instance to convert.

    Returns: The built `ConcurrencyConflict` instance.

    Exceptions: ArgumentNullException: `builder` is `null`

record

ExecuteCasInvocation

Assembly: EricksonLopez.Concurrency.Testing
public sealed record ExecuteCasInvocation(object Entity, ExpectedVersion Expected, string EntityId, DateTimeOffset Timestamp)

Represents an invocation of a CAS operation on `IConcurrencyController`.

Members (5)

  • constructorExecuteCasInvocation
    public ExecuteCasInvocation(object Entity, ExpectedVersion Expected, string EntityId, DateTimeOffset Timestamp)

    Initializes a new instance of ExecuteCasInvocation.

    Entity: object
    The entity instance passed to the CAS operation.
    Expected: ExpectedVersion
    The expected version constraint.
    EntityId: string
    The unique identifier of the entity.
    Timestamp: DateTimeOffset
    The timestamp when the CAS operation was invoked.
  • propertyEntity
    public object Entity { get; init; }

    The entity instance passed to the CAS operation.

  • propertyEntityId
    public string EntityId { get; init; }

    The unique identifier of the entity.

  • propertyExpected
    public ExpectedVersion Expected { get; init; }

    The expected version constraint.

  • propertyTimestamp
    public DateTimeOffset Timestamp { get; init; }

    The timestamp when the CAS operation was invoked.

class

FakeConcurrencyController

Assembly: EricksonLopez.Concurrency.Testing
public sealed class FakeConcurrencyController : IConcurrencyController
Implements: IConcurrencyController

Provides an in-memory, mock-free test double for `IConcurrencyController` with full call tracking and configurable outcomes.

Members (16)

  • methodExecuteCasAsync<TEntity>
    public async ValueTask<CasResult<TEntity>> ExecuteCasAsync<TEntity>(TEntity entity, ExpectedVersion expected, string entityId, Func<TEntity, CancellationToken, ValueTask<TEntity>> mutate, CancellationToken cancellationToken = default) where TEntity : class, IVersionedEntity

    Executes an in-memory optimistic Compare-And-Swap (CAS) state transition on a versioned entity.

    entity: TEntity
    The current entity instance before mutation.
    expected: ExpectedVersion
    The expected version constraint.
    entityId: string
    The unique identifier of the entity.
    mutate: Func<TEntity, CancellationToken, ValueTask<TEntity>>
    The asynchronous mutation delegate that produces the modified entity.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Returns: A value task representing the asynchronous operation. The task result contains the `CasResult<TEntity>` outcome.

    Enforces per-entity mutual exclusion in memory. Invocations on the same `entityId` are strictly non-reentrant; attempting nested or recursive calls to `ExecuteCasAsync` for the same entity identifier within the same asynchronous flow will throw an `InvalidOperationException` to prevent deadlocks. If the target entity implements `IMutableVersionedEntity`, its `IMutableVersionedEntity.Version` is automatically advanced by the controller upon success. If the entity does not implement `IMutableVersionedEntity`, the `mutate` delegate must produce an entity whose version matches the incremented version. Warning (Data Corruption Risk): The `ExecuteCasAsync` method does not provide state rollback. If the `mutate` delegate modifies the entity and subsequently throws an exception, the entity remains in a partially modified state. Always pass a deep clone, use C# 9 `record` copy-semantics (with-expressions), or discard the entity reference on failure. Type parameters: TEntity: The type of the entity implementing `IVersionedEntity`. Exceptions: ArgumentNullException: `entity` or `mutate` is `null`; OperationCanceledException: The cancellation token was canceled

  • methodReset
    public void Reset()

    Clears all recorded invocations and reset configured behaviors to default.

  • methodVerifyToken<TEntity>
    public ConcurrencyConflict? VerifyToken<TEntity>(TEntity entity, IConcurrencyToken expected, string entityId) where TEntity : class, IConcurrencyAware

    Evaluates optimistic concurrency token compatibility against an entity instance.

    entity: TEntity
    The entity instance to verify.
    expected: IConcurrencyToken
    The expected concurrency token constraint.
    entityId: string
    The unique identifier of the entity.

    Returns: A `ConcurrencyConflict` if a token conflict is detected; otherwise, `null`.

    Type parameters: TEntity: The type of the entity implementing `IConcurrencyAware`. Exceptions: ArgumentNullException: `entity` or `expected` is `null`

  • methodVerifyVersion<TEntity>
    public ConcurrencyConflict? VerifyVersion<TEntity>(TEntity entity, ExpectedVersion expected, string entityId) where TEntity : class, IVersionedEntity

    Evaluates optimistic version compatibility against an entity instance.

    entity: TEntity
    The entity instance to verify.
    expected: ExpectedVersion
    The expected version constraint.
    entityId: string
    The unique identifier of the entity.

    Returns: A `ConcurrencyConflict` if a version conflict is detected; otherwise, `null`.

    Type parameters: TEntity: The type of the entity implementing `IVersionedEntity`. Exceptions: ArgumentNullException: `entity` is `null`

  • methodWhenVerifyToken
    public FakeConcurrencyController WhenVerifyToken(Func<object, IConcurrencyToken, string, ConcurrencyConflict?> handler)

    Configures a custom evaluation delegate for `VerifyToken<TEntity>`.

    handler: Func<object, IConcurrencyToken, string, ConcurrencyConflict?>
    The custom delegate evaluating token calls.

    Returns: This `FakeConcurrencyController` instance for fluent chaining.

  • methodWhenVerifyVersion
    public FakeConcurrencyController WhenVerifyVersion(Func<object, ExpectedVersion, string, ConcurrencyConflict?> handler)

    Configures a custom evaluation delegate for `VerifyVersion<TEntity>`.

    handler: Func<object, ExpectedVersion, string, ConcurrencyConflict?>
    The custom delegate evaluating version calls.

    Returns: This `FakeConcurrencyController` instance for fluent chaining.

  • methodWithConflict
    public FakeConcurrencyController WithConflict(ConcurrencyConflict conflict)

    Configures the fake controller to always return the specified conflict on all subsequent operations.

    conflict: ConcurrencyConflict
    The conflict descriptor to return.

    Returns: This `FakeConcurrencyController` instance for fluent chaining.

    Exceptions: ArgumentNullException: `conflict` is `null`

  • methodWithConflict
    public FakeConcurrencyController WithConflict(ConcurrencyConflictType type, string? entityId = null, string? entityType = null, ConcurrencyConflictClassification classification = ConcurrencyConflictClassification.Transient)

    Configures the fake controller to always return a synthesized conflict on all subsequent operations.

    type: ConcurrencyConflictType
    The conflict category.
    entityId: string?
    The optional entity identifier.
    entityType: string?
    The optional entity type name.
    classification: ConcurrencyConflictClassification
    The conflict classification.

    Returns: This `FakeConcurrencyController` instance for fluent chaining.

  • methodWithConflictOnNextWrite
    public FakeConcurrencyController WithConflictOnNextWrite(ConcurrencyConflict conflict)

    Configures the fake controller to return the specified conflict on the next operation only.

    conflict: ConcurrencyConflict
    The conflict descriptor to return.

    Returns: This `FakeConcurrencyController` instance for fluent chaining.

    Exceptions: ArgumentNullException: `conflict` is `null`

  • methodWithConflictOnNextWrite
    public FakeConcurrencyController WithConflictOnNextWrite(ConcurrencyConflictType type, string? entityId = null, string? entityType = null, ConcurrencyConflictClassification classification = ConcurrencyConflictClassification.Transient)

    Configures the fake controller to return a synthesized conflict on the next operation only.

    type: ConcurrencyConflictType
    The conflict category.
    entityId: string?
    The optional entity identifier.
    entityType: string?
    The optional entity type name.
    classification: ConcurrencyConflictClassification
    The conflict classification.

    Returns: This `FakeConcurrencyController` instance for fluent chaining.

  • methodWithSuccess
    public FakeConcurrencyController WithSuccess(long? nextVersion = null)

    Configures the fake controller to produce a successful outcome on all subsequent operations.

    nextVersion: long?
    The version value to return on CAS operations, or `null` to increment automatically.

    Returns: This `FakeConcurrencyController` instance for fluent chaining.

  • methodWithSuccessOnNextWrite
    public FakeConcurrencyController WithSuccessOnNextWrite(long? nextVersion = null)

    Configures the fake controller to enqueue a specific successful version for the next operation.

    nextVersion: long?
    The specific version value to return on the next CAS operation.

    Returns: This `FakeConcurrencyController` instance for fluent chaining.

  • propertyExecuteCasInvocations
    public IReadOnlyList<ExecuteCasInvocation> ExecuteCasInvocations { get; }

    Gets the list of recorded CAS invocations.

  • propertyTotalInvocations
    public int TotalInvocations { get; }

    Gets the total number of invocations across all methods.

  • propertyVerifyTokenInvocations
    public IReadOnlyList<VerifyTokenInvocation> VerifyTokenInvocations { get; }

    Gets the list of recorded `IConcurrencyController.VerifyToken<TEntity>` invocations.

  • propertyVerifyVersionInvocations
    public IReadOnlyList<VerifyVersionInvocation> VerifyVersionInvocations { get; }

    Gets the list of recorded `IConcurrencyController.VerifyVersion<TEntity>` invocations.

record

VerifyTokenInvocation

Assembly: EricksonLopez.Concurrency.Testing
public sealed record VerifyTokenInvocation(object Entity, IConcurrencyToken Expected, string EntityId, DateTimeOffset Timestamp)

Represents a recorded invocation of `IConcurrencyController.VerifyToken<TEntity>`.

Members (5)

  • constructorVerifyTokenInvocation
    public VerifyTokenInvocation(object Entity, IConcurrencyToken Expected, string EntityId, DateTimeOffset Timestamp)

    Initializes a new instance of VerifyTokenInvocation.

    Entity: object
    The entity instance passed to verification.
    Expected: IConcurrencyToken
    The expected token constraint.
    EntityId: string
    The unique identifier of the entity.
    Timestamp: DateTimeOffset
    The timestamp when the verification was invoked.
  • propertyEntity
    public object Entity { get; init; }

    The entity instance passed to verification.

  • propertyEntityId
    public string EntityId { get; init; }

    The unique identifier of the entity.

  • propertyExpected
    public IConcurrencyToken Expected { get; init; }

    The expected token constraint.

  • propertyTimestamp
    public DateTimeOffset Timestamp { get; init; }

    The timestamp when the verification was invoked.

record

VerifyVersionInvocation

Assembly: EricksonLopez.Concurrency.Testing
public sealed record VerifyVersionInvocation(object Entity, ExpectedVersion Expected, string EntityId, DateTimeOffset Timestamp)

Represents a recorded invocation of `IConcurrencyController.VerifyVersion<TEntity>`.

Members (5)

  • constructorVerifyVersionInvocation
    public VerifyVersionInvocation(object Entity, ExpectedVersion Expected, string EntityId, DateTimeOffset Timestamp)

    Initializes a new instance of VerifyVersionInvocation.

    Entity: object
    The entity instance passed to verification.
    Expected: ExpectedVersion
    The expected version constraint.
    EntityId: string
    The unique identifier of the entity.
    Timestamp: DateTimeOffset
    The timestamp when the verification was invoked.
  • propertyEntity
    public object Entity { get; init; }

    The entity instance passed to verification.

  • propertyEntityId
    public string EntityId { get; init; }

    The unique identifier of the entity.

  • propertyExpected
    public ExpectedVersion Expected { get; init; }

    The expected version constraint.

  • propertyTimestamp
    public DateTimeOffset Timestamp { get; init; }

    The timestamp when the verification was invoked.

Search EricksonLopez.* Ecosystem

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