Referencia Pública de API .NETL2 Transversal y FiabilidadEstableAOT: Completo

EricksonLopez.DistributedLock

High-performance distributed locking & mutual exclusion ecosystem for .NET 8/9/10. Zero-exception Result pattern, Native AOT compliant, OpenTelemetry metrics, and native providers for PostgreSQL, SQL Server, MySQL, MariaDB, Oracle, SQLite, and Redis.

9 namespaces43 tipos225 miembrosGenerado desde XML docs y ensamblados · UTC 2026-12-01

Mostrando 43 de 43 tipos (225 miembros)

EricksonLopez.DistributedLock.Abstractions#

7
class

CompositeDistributedLockHandle

Ensamblado: EricksonLopez.DistributedLock.Abstractions
public sealed class CompositeDistributedLockHandle : IDistributedLockHandle
Implementa: IDistributedLockHandle

Represents a composite distributed lock handle holding multiple underlying resource locks acquired in canonical order.

Miembros (6)

  • constructorCompositeDistributedLockHandle
    public CompositeDistributedLockHandle(IReadOnlyList<string> canonicalResourceIds, IReadOnlyList<IDistributedLockHandle> handles)

    Initializes a new instance of the `CompositeDistributedLockHandle` class.

    canonicalResourceIds: IReadOnlyList<string>
    The list of canonicalized resource identifiers.
    handles: IReadOnlyList<IDistributedLockHandle>
    The acquired individual lock handles.
  • methodDisposeAsync
    public async ValueTask DisposeAsync()

    Inherits documentation from base type or interface.

  • propertyFencingToken
    public long? FencingToken { get; }

    Gets an optional monotonic fencing token associated with this lock acquisition.

    Enables downstream resource validation against stale split-brain writes. Returns `null` if the underlying locking engine does not support monotonic fencing tokens.

  • propertyHandleLostToken
    public CancellationToken HandleLostToken { get; }

    Gets a cancellation token that is canceled if lock ownership is lost unexpectedly.

    Triggered by unexpected events such as connection drops, server failovers, or keepalive timeouts.

  • propertyLockId
    public long LockId { get; }

    Gets the 64-bit numerical identifier derived for this lock.

    This value is an identifier derived deterministically from `ResourceId`, not a monotonic fencing token. For fencing verification against stale writes, see `FencingToken`. Sentinel value: Adapter implementations (such as internal fallback handles) may return `0` as a sentinel value when no numeric lock identifier is applicable. Consumers that inspect `LockId` should treat `0` as an uninitialized or non-applicable identifier.

  • propertyResourceId
    public string ResourceId { get; }

    Gets the unique identifier of the resource associated with this lock.

class

DistributedLockAttribute

Ensamblado: EricksonLopez.DistributedLock.Abstractions
public sealed class DistributedLockAttribute : Attribute
Hereda de: Attribute

Specifies declarative distributed mutual exclusion for target classes or methods.

Miembros (4)

  • constructorDistributedLockAttribute
    public DistributedLockAttribute(string resourceKeyPattern)

    Initializes a new instance of the `DistributedLockAttribute` class with the specified resource key pattern.

    resourceKeyPattern: string
    The template or literal key identifying the resource to lock.

    Exceptions: ArgumentException: `resourceKeyPattern` is empty or contains only white space

  • propertyBlocking
    public bool Blocking { get; set; }

    Gets or sets a value indicating whether lock acquisition should block until granted.

    When set to `true`, the operation blocks until granted or until bounded by `TimeoutSeconds`.

  • propertyResourceKeyPattern
    public string ResourceKeyPattern { get; }

    Gets the template or literal key pattern for the resource.

  • propertyTimeoutSeconds
    public int TimeoutSeconds { get; set; }

    Gets or sets the maximum duration in seconds to wait for lock acquisition.

    A value of zero specifies an immediate, non-blocking acquisition attempt. Defaults to zero.

class

DistributedLockErrors

Ensamblado: EricksonLopez.DistributedLock.Abstractions
public static class DistributedLockErrors

Provides predefined standard domain errors for distributed locking failures.

Miembros (5)

  • fieldCanceled
    public static readonly Error Canceled

    Represents a domain error indicating that the lock acquisition operation was canceled.

  • fieldDeadlockVictim
    public static readonly Error DeadlockVictim

    Represents a domain error indicating that the lock acquisition was aborted because the session was selected as a deadlock victim.

  • fieldLockAlreadyHeld
    public static readonly Error LockAlreadyHeld

    Represents a domain error indicating that the requested lock is already held by another owner.

  • fieldLockLost
    public static readonly Error LockLost

    Represents a domain error indicating that lock ownership was lost unexpectedly due to session or network termination.

  • fieldTimeout
    public static readonly Error Timeout

    Represents a domain error indicating that the lock could not be acquired within the allocated duration.

class

DistributedLockExtensions

Ensamblado: EricksonLopez.DistributedLock.Abstractions
public static class DistributedLockExtensions

Provides extension methods for `IDistributedLockProvider` to execute operations within a distributed lock scope.

Miembros (6)

  • methodAcquireAllAsync
    public static Task<Result<IDistributedLockHandle>> AcquireAllAsync(this IDistributedLockProvider provider, IEnumerable<string> resourceIds, CancellationToken cancellationToken = default)

    Acquires locks for multiple resources using deterministic canonical ordering (Ordinal) to prevent deadlocks.

    provider: this IDistributedLockProvider
    The distributed lock provider.
    resourceIds: IEnumerable<string>
    The collection of resource identifiers to lock.
    cancellationToken: CancellationToken
    A token to cancel the operation.

    Retorna: A composite lock handle representing all acquired resources.

  • methodAcquireAllAsync
    public static async Task<Result<IDistributedLockHandle>> AcquireAllAsync(this IDistributedLockProvider provider, IEnumerable<string> resourceIds, TimeSpan timeout, CancellationToken cancellationToken = default)

    Acquires locks for multiple resources within a maximum timeout using deterministic canonical ordering (Ordinal).

    provider: this IDistributedLockProvider
    The distributed lock provider.
    resourceIds: IEnumerable<string>
    The collection of resource identifiers to lock.
    timeout: TimeSpan
    The maximum duration to wait for each lock acquisition.
    cancellationToken: CancellationToken
    A token to cancel the operation.

    Retorna: A composite lock handle representing all acquired resources, or failure if any lock cannot be acquired.

  • methodExecuteWithLockAsync
    public static async Task<Result<bool>> ExecuteWithLockAsync(this IDistributedLockProvider provider, string resourceId, Func<CancellationToken, Task> action, CancellationToken cancellationToken = default)

    Executes an asynchronous action within the scope of an acquired distributed lock.

    provider: this IDistributedLockProvider
    The distributed lock provider.
    resourceId: string
    The unique identifier of the resource to lock.
    action: Func<CancellationToken, Task>
    The asynchronous operation to execute within the lock scope.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with `true` if the lock was acquired and the operation executed; otherwise, the acquisition error.

    The lock handle is disposed upon completion. The delegate receives a token linked to `IDistributedLockHandle.HandleLostToken`. Exceptions: ArgumentNullException: `provider` or `action` is `null`; ArgumentException: `resourceId` is empty or contains only white space

  • methodExecuteWithLockAsync
    public static async Task<Result<bool>> ExecuteWithLockAsync(this IDistributedLockProvider provider, string resourceId, TimeSpan timeout, Func<CancellationToken, Task> action, CancellationToken cancellationToken = default)

    Executes an asynchronous action within the scope of a distributed lock, waiting up to the specified timeout.

    provider: this IDistributedLockProvider
    The distributed lock provider.
    resourceId: string
    The unique identifier of the resource to lock.
    timeout: TimeSpan
    The maximum duration to wait for lock acquisition.
    action: Func<CancellationToken, Task>
    The asynchronous operation to execute within the lock scope.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with `true` if the lock was acquired and the operation executed; otherwise, the acquisition error.

    The lock handle is disposed upon completion. The delegate receives a token linked to `IDistributedLockHandle.HandleLostToken`. Exceptions: ArgumentNullException: `provider` or `action` is `null`; ArgumentException: `resourceId` is empty or contains only white space

  • methodExecuteWithLockAsync<T>
    public static async Task<Result<T>> ExecuteWithLockAsync<T>(this IDistributedLockProvider provider, string resourceId, Func<CancellationToken, Task<T>> action, CancellationToken cancellationToken = default)

    Executes an asynchronous function returning a value within the scope of an acquired distributed lock.

    provider: this IDistributedLockProvider
    The distributed lock provider.
    resourceId: string
    The unique identifier of the resource to lock.
    action: Func<CancellationToken, Task<T>>
    The asynchronous function returning a value to execute within the lock scope.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with the value produced by the action if acquired; otherwise, the acquisition error.

    The lock handle is disposed upon completion. The delegate receives a token linked to `IDistributedLockHandle.HandleLostToken`. Type parameters: T: The type of the result produced by the action. Exceptions: ArgumentNullException: `provider` or `action` is `null`; ArgumentException: `resourceId` is empty or contains only white space

  • methodExecuteWithLockAsync<T>
    public static async Task<Result<T>> ExecuteWithLockAsync<T>(this IDistributedLockProvider provider, string resourceId, TimeSpan timeout, Func<CancellationToken, Task<T>> action, CancellationToken cancellationToken = default)

    Executes an asynchronous function returning a value within the scope of a distributed lock, waiting up to the specified timeout for acquisition.

    provider: this IDistributedLockProvider
    The distributed lock provider.
    resourceId: string
    The unique identifier of the resource to lock.
    timeout: TimeSpan
    The maximum duration to wait for lock acquisition.
    action: Func<CancellationToken, Task<T>>
    The asynchronous function returning a value to execute within the lock scope.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with the value produced by the action if the lock was acquired within the timeout; otherwise, the acquisition error.

    The lock handle is disposed upon completion. The delegate receives a token linked to `IDistributedLockHandle.HandleLostToken`. Type parameters: T: The type of the result produced by the action. Exceptions: ArgumentNullException: `provider` or `action` is `null`; ArgumentException: `resourceId` is empty or contains only white space

class

DistributedLockMetrics

Ensamblado: EricksonLopez.DistributedLock.Abstractions
public static class DistributedLockMetrics

Provides OpenTelemetry instrumentation and metrics for distributed lock operations.

Miembros (6)

  • methodRecordAcquisition
    public static void RecordAcquisition(string resourceId, string lockType, string status)

    Records a distributed lock acquisition attempt and its outcome.

    resourceId: string
    The unique identifier of the resource for which the lock was attempted.
    lockType: string
    The type of lock attempted. Canonical values include "session" or "transaction".
    status: string
    The outcome status of the acquisition attempt.
  • methodRecordHoldDuration
    public static void RecordHoldDuration(string resourceId, string lockType, double durationMs)

    Records the duration for which an acquired distributed lock was held prior to disposal.

    resourceId: string
    The unique identifier of the resource whose lock was held.
    lockType: string
    The type of lock held. Canonical values include "session" or "transaction".
    durationMs: double
    The duration in milliseconds the lock was held.
  • methodRecordLockLost
    public static void RecordLockLost(string resourceId, long lockId)

    Records an unexpected loss of distributed lock ownership.

    resourceId: string
    The unique identifier of the resource whose lock was lost.
    lockId: long
    The 64-bit numerical identifier of the lost lock.
  • methodRecordWaitDuration
    public static void RecordWaitDuration(string resourceId, string lockType, string status, double durationMs)

    Records the duration spent waiting to acquire a distributed lock.

    resourceId: string
    The unique identifier of the resource for which the lock was attempted.
    lockType: string
    The type of lock attempted. Canonical values include "session" or "transaction".
    status: string
    The outcome status of the acquisition attempt.
    durationMs: double
    The elapsed duration in milliseconds spent waiting.
  • fieldMeterName
    public const string MeterName

    Gets the name of the OpenTelemetry meter for distributed lock telemetry.

  • fieldMeterVersion
    public const string MeterVersion

    Gets the version of the OpenTelemetry meter for distributed lock telemetry.

interface

IDistributedLockHandle

Ensamblado: EricksonLopez.DistributedLock.Abstractions
public interface IDistributedLockHandle : IAsyncDisposable
Implementa: IAsyncDisposable

Defines a contract for a distributed lock handle whose disposal releases the acquired lock.

Miembros (4)

  • propertyFencingToken
    long? FencingToken { get; }

    Gets an optional monotonic fencing token associated with this lock acquisition.

    Enables downstream resource validation against stale split-brain writes. Returns `null` if the underlying locking engine does not support monotonic fencing tokens.

  • propertyHandleLostToken
    CancellationToken HandleLostToken { get; }

    Gets a cancellation token that is canceled if lock ownership is lost unexpectedly.

    Triggered by unexpected events such as connection drops, server failovers, or keepalive timeouts.

  • propertyLockId
    long LockId { get; }

    Gets the 64-bit numerical identifier derived for this lock.

    This value is an identifier derived deterministically from `ResourceId`, not a monotonic fencing token. For fencing verification against stale writes, see `FencingToken`. Sentinel value: Adapter implementations (such as internal fallback handles) may return `0` as a sentinel value when no numeric lock identifier is applicable. Consumers that inspect `LockId` should treat `0` as an uninitialized or non-applicable identifier.

  • propertyResourceId
    string ResourceId { get; }

    Gets the unique identifier of the resource associated with this lock.

interface

IDistributedLockProvider

Ensamblado: EricksonLopez.DistributedLock.Abstractions
public interface IDistributedLockProvider

Defines a contract for coordinating distributed mutual exclusion across process boundaries.

Miembros (8)

  • methodAcquireAsync
    Task<Result<IAsyncDisposable>> AcquireAsync(string resourceId, CancellationToken cancellationToken = default)

    Acquires a distributed lock for the specified resource, blocking until the lock is granted.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if acquired; otherwise, the acquisition error.

    The default interface implementation delegates to `TryAcquireAsync(string, TimeSpan, CancellationToken)` with `Timeout.InfiniteTimeSpan`. Concrete implementations may override this method to use native engine blocking primitives.

  • methodAcquireAsync
    Task<Result<IAsyncDisposable>> AcquireAsync(string resourceId, TimeSpan timeout, CancellationToken cancellationToken = default)

    Acquires a distributed lock for the specified resource, blocking until granted or timeout expires.

    resourceId: string
    The unique identifier of the resource to lock.
    timeout: TimeSpan
    The maximum duration to wait for the lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if acquired; otherwise, the acquisition error.

    The default interface implementation delegates to `TryAcquireAsync(string, TimeSpan, CancellationToken)`. Concrete implementations may override this method to use provider-specific bounded-wait mechanisms.

  • methodAcquireHandleAsync
    async Task<Result<IDistributedLockHandle>> AcquireHandleAsync(string resourceId, CancellationToken cancellationToken = default)

    Acquires a strongly typed distributed lock handle, blocking until the lock is granted.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

  • methodAcquireHandleAsync
    async Task<Result<IDistributedLockHandle>> AcquireHandleAsync(string resourceId, TimeSpan timeout, CancellationToken cancellationToken = default)

    Acquires a strongly typed distributed lock handle, blocking until granted or timeout expires.

    resourceId: string
    The unique identifier of the resource to lock.
    timeout: TimeSpan
    The maximum duration to wait for the lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

  • methodTryAcquireAsync
    Task<Result<IAsyncDisposable>> TryAcquireAsync(string resourceId, CancellationToken cancellationToken = default)

    Attempts to acquire a distributed lock for the specified resource immediately without waiting.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if the lock was acquired; otherwise, a failure with `DistributedLockErrors.LockAlreadyHeld`.

  • methodTryAcquireAsync
    Task<Result<IAsyncDisposable>> TryAcquireAsync(string resourceId, TimeSpan timeout, CancellationToken cancellationToken = default)

    Attempts to acquire a distributed lock for the specified resource within a maximum duration.

    resourceId: string
    The unique identifier of the resource to lock.
    timeout: TimeSpan
    The maximum duration to wait for the lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if the lock was acquired; otherwise, a failure with `DistributedLockErrors.Timeout`.

  • methodTryAcquireHandleAsync
    async Task<Result<IDistributedLockHandle>> TryAcquireHandleAsync(string resourceId, CancellationToken cancellationToken = default)

    Attempts to acquire a strongly typed distributed lock handle immediately without waiting.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

  • methodTryAcquireHandleAsync
    async Task<Result<IDistributedLockHandle>> TryAcquireHandleAsync(string resourceId, TimeSpan timeout, CancellationToken cancellationToken = default)

    Attempts to acquire a strongly typed distributed lock handle within a maximum duration.

    resourceId: string
    The unique identifier of the resource to lock.
    timeout: TimeSpan
    The maximum duration to wait for the lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

EricksonLopez.DistributedLock.MariaDb#

4
class

MariaDbDistributedLockHandle

Ensamblado: EricksonLopez.DistributedLock.MariaDb
public sealed class MariaDbDistributedLockHandle : IDistributedLockHandle
Implementa: IDistributedLockHandle

Represents an active MariaDB user-level lock handle that releases the lock upon disposal.

Miembros (5)

  • constructorMariaDbDistributedLockHandle
    public MariaDbDistributedLockHandle(DbConnection connection, string lockResource, string resourceId, ILogger logger, TimeSpan? keepaliveCadence = null, int commandTimeoutSeconds = 30)

    Initializes a new instance of the `MariaDbDistributedLockHandle` class with the specified connection and lock parameters.

    connection: DbConnection
    The underlying database connection holding the user-level lock.
    lockResource: string
    The database-level lock resource identifier.
    resourceId: string
    The logical resource identifier requested by the caller.
    logger: ILogger
    The logger used for recording diagnostic and lifecycle events.
    keepaliveCadence: TimeSpan?
    The optional interval for heartbeat queries to detect dropped connections.
    commandTimeoutSeconds: int
    The command timeout in seconds for lock maintenance commands.

    Exceptions: ArgumentNullException: `connection`, `lockResource`, `resourceId`, or `logger` is `null`

  • methodDisposeAsync
    public async ValueTask DisposeAsync()

    Inherits documentation from base type or interface.

  • propertyHandleLostToken
    public CancellationToken HandleLostToken { get; }

    Gets a cancellation token that is canceled if lock ownership is lost unexpectedly.

    Triggered by unexpected events such as connection drops, server failovers, or keepalive timeouts.

  • propertyLockId
    public long LockId { get; }

    Gets the 64-bit numerical identifier derived for this lock.

    This value is an identifier derived deterministically from `ResourceId`, not a monotonic fencing token. For fencing verification against stale writes, see `FencingToken`. Sentinel value: Adapter implementations (such as internal fallback handles) may return `0` as a sentinel value when no numeric lock identifier is applicable. Consumers that inspect `LockId` should treat `0` as an uninitialized or non-applicable identifier.

  • propertyResourceId
    public string ResourceId { get; }

    Gets the unique identifier of the resource associated with this lock.

class

MariaDbDistributedLockProvider

Ensamblado: EricksonLopez.DistributedLock.MariaDb
public sealed class MariaDbDistributedLockProvider : IDistributedLockProvider
Implementa: IDistributedLockProvider

Provides distributed locks backed by MariaDB user-level locking functions.

Miembros (9)

  • constructorMariaDbDistributedLockProvider
    public MariaDbDistributedLockProvider(Func<DbConnection> connectionFactory, ILogger<MariaDbDistributedLockProvider> logger, IOptions<MariaDbLockOptions> options)

    Initializes a new instance of the `MariaDbDistributedLockProvider` class configured via options snapshot.

    connectionFactory: Func<DbConnection>
    The delegate producing dedicated database connections per lock handle.
    logger: ILogger<MariaDbDistributedLockProvider>
    The logger used for recording diagnostic and lifecycle events.
    options: IOptions<MariaDbLockOptions>
    The configuration options accessor.

    Exceptions: ArgumentNullException: `connectionFactory` or `logger` is `null`

  • constructorMariaDbDistributedLockProvider
    public MariaDbDistributedLockProvider(Func<DbConnection> connectionFactory, ILogger<MariaDbDistributedLockProvider> logger, MariaDbLockOptions? options = null)

    Initializes a new instance of the `MariaDbDistributedLockProvider` class using a connection factory for dedicated sessions.

    connectionFactory: Func<DbConnection>
    The delegate producing dedicated database connections per lock handle.
    logger: ILogger<MariaDbDistributedLockProvider>
    The logger used for recording diagnostic and lifecycle events.
    options: MariaDbLockOptions?
    The configuration options for lock acquisition and keepalive.

    Exceptions: ArgumentNullException: `connectionFactory` or `logger` is `null`

  • constructorMariaDbDistributedLockProvider
    public MariaDbDistributedLockProvider(IDbConnection connection, ILogger<MariaDbDistributedLockProvider> logger, MariaDbLockOptions? options = null)

    Initializes a new instance of the `MariaDbDistributedLockProvider` class using an existing database connection.

    connection: IDbConnection
    The database connection used for ambient session locks.
    logger: ILogger<MariaDbDistributedLockProvider>
    The logger used for recording diagnostic and lifecycle events.
    options: MariaDbLockOptions?
    The configuration options for lock acquisition and keepalive.

    Exceptions: ArgumentNullException: `connection` or `logger` is `null`

  • methodAcquireAsync
    public async Task<Result<IAsyncDisposable>> AcquireAsync(string resourceId, CancellationToken cancellationToken = default)

    Acquires a distributed lock for the specified resource, blocking until the lock is granted.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if acquired; otherwise, the acquisition error.

    The default interface implementation delegates to `TryAcquireAsync(string, TimeSpan, CancellationToken)` with `Timeout.InfiniteTimeSpan`. Concrete implementations may override this method to use native engine blocking primitives.

  • methodAcquireHandleAsync
    public async Task<Result<IDistributedLockHandle>> AcquireHandleAsync(string resourceId, CancellationToken cancellationToken = default)

    Acquires a strongly typed distributed lock handle, blocking until the lock is granted.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

  • methodTryAcquireAsync
    public async Task<Result<IAsyncDisposable>> TryAcquireAsync(string resourceId, CancellationToken cancellationToken = default)

    Attempts to acquire a distributed lock for the specified resource immediately without waiting.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if the lock was acquired; otherwise, a failure with `DistributedLockErrors.LockAlreadyHeld`.

  • methodTryAcquireAsync
    public async Task<Result<IAsyncDisposable>> TryAcquireAsync(string resourceId, TimeSpan timeout, CancellationToken cancellationToken = default)

    Attempts to acquire a distributed lock for the specified resource within a maximum duration.

    resourceId: string
    The unique identifier of the resource to lock.
    timeout: TimeSpan
    The maximum duration to wait for the lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if the lock was acquired; otherwise, a failure with `DistributedLockErrors.Timeout`.

  • methodTryAcquireHandleAsync
    public async Task<Result<IDistributedLockHandle>> TryAcquireHandleAsync(string resourceId, CancellationToken cancellationToken = default)

    Attempts to acquire a strongly typed distributed lock handle immediately without waiting.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

  • methodTryAcquireHandleAsync
    public async Task<Result<IDistributedLockHandle>> TryAcquireHandleAsync(string resourceId, TimeSpan timeout, CancellationToken cancellationToken = default)

    Attempts to acquire a strongly typed distributed lock handle within a maximum duration.

    resourceId: string
    The unique identifier of the resource to lock.
    timeout: TimeSpan
    The maximum duration to wait for the lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

class

MariaDbLockOptions

Ensamblado: EricksonLopez.DistributedLock.MariaDb
public sealed class MariaDbLockOptions

Specifies configuration options for the MariaDB distributed lock provider.

Miembros (7)

  • propertyBackoffJitter
    public bool BackoffJitter { get; set; }

    Gets or sets a value indicating whether random jitter is added to retry intervals.

    Retained for backward compatibility. This property is unused because the database engine natively coordinates lock waiting on the server side.

  • propertyCommandTimeoutSeconds
    public int CommandTimeoutSeconds { get; set; }

    Gets or sets the command timeout in seconds for lock maintenance commands.

    The default value is 30 seconds.

  • propertyDatabaseScope
    public string? DatabaseScope { get; set; }

    Gets or sets an explicit namespace or tenant prefix prepended to the lock resource name.

  • propertyKeepaliveCadence
    public TimeSpan? KeepaliveCadence { get; set; }

    Gets or sets the cadence for sending keepalive heartbeat queries over held session connections.

    When set to `null`, keepalive heartbeats are disabled. Defaults to 10 seconds.

  • propertyMaxAcquisitionTimeoutSeconds
    public int MaxAcquisitionTimeoutSeconds { get; set; }

    Gets or sets the acquisition timeout chunk in seconds for blocking acquisition calls (AcquireHandleAsync). Prevents 68-year permanent hangs in MariaDB metadata locks. The default value is 300 seconds (5 minutes).

  • propertyRetryInterval
    public TimeSpan RetryInterval { get; set; }

    Gets or sets the base polling interval when waiting for a lock with timeout.

    Retained for backward compatibility. This property is unused because the database engine natively coordinates lock waiting on the server side.

  • propertyScopeToDatabase
    public bool ScopeToDatabase { get; set; }

    Gets or sets a value indicating whether the connection's database catalog name should be prepended to the lock resource name to scope locks to the database in MariaDB's global instance namespace. The default value is `false` for backward compatibility.

class

MariaDbTransactionLockExtensions

Ensamblado: EricksonLopez.DistributedLock.MariaDb
public static class MariaDbTransactionLockExtensions

Provides extension methods for acquiring MariaDB locks within active database transactions.

Miembros (4)

  • methodAcquireInTransactionAsync
    public static Task<Result<IDistributedLockHandle>> AcquireInTransactionAsync(this DbTransaction transaction, string resourceId, ILogger logger, CancellationToken cancellationToken = default)

    Acquires an exclusive transaction-scoped lock on the specified `DbTransaction`, blocking until granted.

    transaction: this DbTransaction
    The active database transaction to bind the lock to.
    resourceId: string
    The unique identifier of the resource to lock.
    logger: ILogger
    The logger used for recording diagnostic and lifecycle events.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

    Exceptions: ArgumentNullException: `transaction` or `logger` is `null`; ArgumentException: `resourceId` is empty or contains only white space; InvalidOperationException: The connection associated with `transaction` is `null`

  • methodAcquireInTransactionAsync
    public static async Task<Result<IDistributedLockHandle>> AcquireInTransactionAsync(this IDbTransaction transaction, string resourceId, ILogger logger, CancellationToken cancellationToken = default)

    Acquires an exclusive transaction-scoped lock on the specified MariaDB transaction, blocking until granted.

    transaction: this IDbTransaction
    The active database transaction to bind the lock to.
    resourceId: string
    The unique identifier of the resource to lock.
    logger: ILogger
    The logger used for recording diagnostic and lifecycle events.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

    Exceptions: ArgumentNullException: `transaction` or `logger` is `null`; ArgumentException: `resourceId` is empty or contains only white space; InvalidOperationException: The connection associated with `transaction` is `null`

  • methodTryAcquireInTransactionAsync
    public static Task<Result<IDistributedLockHandle>> TryAcquireInTransactionAsync(this DbTransaction transaction, string resourceId, ILogger logger, CancellationToken cancellationToken = default)

    Attempts to acquire an exclusive transaction-scoped lock on the specified `DbTransaction` immediately.

    transaction: this DbTransaction
    The active database transaction to bind the lock to.
    resourceId: string
    The unique identifier of the resource to lock.
    logger: ILogger
    The logger used for recording diagnostic and lifecycle events.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if the lock was acquired; otherwise, a failure with `DistributedLockErrors.LockAlreadyHeld`.

    Exceptions: ArgumentNullException: `transaction` or `logger` is `null`; ArgumentException: `resourceId` is empty or contains only white space; InvalidOperationException: The connection associated with `transaction` is `null`

  • methodTryAcquireInTransactionAsync
    public static async Task<Result<IDistributedLockHandle>> TryAcquireInTransactionAsync(this IDbTransaction transaction, string resourceId, ILogger logger, CancellationToken cancellationToken = default)

    Attempts to acquire an exclusive transaction-scoped lock on the specified MariaDB transaction immediately.

    transaction: this IDbTransaction
    The active database transaction to bind the lock to.
    resourceId: string
    The unique identifier of the resource to lock.
    logger: ILogger
    The logger used for recording diagnostic and lifecycle events.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if the lock was acquired; otherwise, a failure with `DistributedLockErrors.LockAlreadyHeld`.

    Exceptions: ArgumentNullException: `transaction` or `logger` is `null`; ArgumentException: `resourceId` is empty or contains only white space; InvalidOperationException: The connection associated with `transaction` is `null`

EricksonLopez.DistributedLock.MySql#

4
class

MySqlDistributedLockHandle

Ensamblado: EricksonLopez.DistributedLock.MySql
public sealed class MySqlDistributedLockHandle : IDistributedLockHandle
Implementa: IDistributedLockHandle

Represents an active MySQL user-level lock handle that releases the lock upon disposal.

Miembros (5)

  • constructorMySqlDistributedLockHandle
    public MySqlDistributedLockHandle(DbConnection connection, string lockResource, string resourceId, ILogger logger, TimeSpan? keepaliveCadence = null, int commandTimeoutSeconds = 30)

    Initializes a new instance of the `MySqlDistributedLockHandle` class with the specified connection and lock parameters.

    connection: DbConnection
    The underlying database connection holding the user-level lock.
    lockResource: string
    The database-level lock resource identifier.
    resourceId: string
    The logical resource identifier requested by the caller.
    logger: ILogger
    The logger used for recording diagnostic and lifecycle events.
    keepaliveCadence: TimeSpan?
    The optional interval for heartbeat queries to detect dropped connections.
    commandTimeoutSeconds: int
    The command timeout in seconds for lock maintenance commands.

    Exceptions: ArgumentNullException: `connection`, `lockResource`, `resourceId`, or `logger` is `null`

  • methodDisposeAsync
    public async ValueTask DisposeAsync()

    Inherits documentation from base type or interface.

  • propertyHandleLostToken
    public CancellationToken HandleLostToken { get; }

    Gets a cancellation token that is canceled if lock ownership is lost unexpectedly.

    Triggered by unexpected events such as connection drops, server failovers, or keepalive timeouts.

  • propertyLockId
    public long LockId { get; }

    Gets the 64-bit numerical identifier derived for this lock.

    This value is an identifier derived deterministically from `ResourceId`, not a monotonic fencing token. For fencing verification against stale writes, see `FencingToken`. Sentinel value: Adapter implementations (such as internal fallback handles) may return `0` as a sentinel value when no numeric lock identifier is applicable. Consumers that inspect `LockId` should treat `0` as an uninitialized or non-applicable identifier.

  • propertyResourceId
    public string ResourceId { get; }

    Gets the unique identifier of the resource associated with this lock.

class

MySqlDistributedLockProvider

Ensamblado: EricksonLopez.DistributedLock.MySql
public sealed class MySqlDistributedLockProvider : IDistributedLockProvider
Implementa: IDistributedLockProvider

Provides distributed locks backed by MySQL user-level locking functions.

Miembros (9)

  • constructorMySqlDistributedLockProvider
    public MySqlDistributedLockProvider(Func<DbConnection> connectionFactory, ILogger<MySqlDistributedLockProvider> logger, IOptions<MySqlLockOptions> options)

    Initializes a new instance of the `MySqlDistributedLockProvider` class configured via options snapshot.

    connectionFactory: Func<DbConnection>
    The delegate producing dedicated database connections per lock handle.
    logger: ILogger<MySqlDistributedLockProvider>
    The logger used for recording diagnostic and lifecycle events.
    options: IOptions<MySqlLockOptions>
    The configuration options accessor.

    Exceptions: ArgumentNullException: `connectionFactory` or `logger` is `null`

  • constructorMySqlDistributedLockProvider
    public MySqlDistributedLockProvider(Func<DbConnection> connectionFactory, ILogger<MySqlDistributedLockProvider> logger, MySqlLockOptions? options = null)

    Initializes a new instance of the `MySqlDistributedLockProvider` class using a connection factory for dedicated sessions.

    connectionFactory: Func<DbConnection>
    The delegate producing dedicated database connections per lock handle.
    logger: ILogger<MySqlDistributedLockProvider>
    The logger used for recording diagnostic and lifecycle events.
    options: MySqlLockOptions?
    The configuration options for lock acquisition and keepalive.

    Exceptions: ArgumentNullException: `connectionFactory` or `logger` is `null`

  • constructorMySqlDistributedLockProvider
    public MySqlDistributedLockProvider(IDbConnection connection, ILogger<MySqlDistributedLockProvider> logger, MySqlLockOptions? options = null)

    Initializes a new instance of the `MySqlDistributedLockProvider` class using an existing database connection.

    connection: IDbConnection
    The database connection used for ambient session locks.
    logger: ILogger<MySqlDistributedLockProvider>
    The logger used for recording diagnostic and lifecycle events.
    options: MySqlLockOptions?
    The configuration options for lock acquisition and keepalive.

    Exceptions: ArgumentNullException: `connection` or `logger` is `null`

  • methodAcquireAsync
    public async Task<Result<IAsyncDisposable>> AcquireAsync(string resourceId, CancellationToken cancellationToken = default)

    Acquires a distributed lock for the specified resource, blocking until the lock is granted.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if acquired; otherwise, the acquisition error.

    The default interface implementation delegates to `TryAcquireAsync(string, TimeSpan, CancellationToken)` with `Timeout.InfiniteTimeSpan`. Concrete implementations may override this method to use native engine blocking primitives.

  • methodAcquireHandleAsync
    public async Task<Result<IDistributedLockHandle>> AcquireHandleAsync(string resourceId, CancellationToken cancellationToken = default)

    Acquires a strongly typed distributed lock handle, blocking until the lock is granted.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

  • methodTryAcquireAsync
    public async Task<Result<IAsyncDisposable>> TryAcquireAsync(string resourceId, CancellationToken cancellationToken = default)

    Attempts to acquire a distributed lock for the specified resource immediately without waiting.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if the lock was acquired; otherwise, a failure with `DistributedLockErrors.LockAlreadyHeld`.

  • methodTryAcquireAsync
    public async Task<Result<IAsyncDisposable>> TryAcquireAsync(string resourceId, TimeSpan timeout, CancellationToken cancellationToken = default)

    Attempts to acquire a distributed lock for the specified resource within a maximum duration.

    resourceId: string
    The unique identifier of the resource to lock.
    timeout: TimeSpan
    The maximum duration to wait for the lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if the lock was acquired; otherwise, a failure with `DistributedLockErrors.Timeout`.

  • methodTryAcquireHandleAsync
    public async Task<Result<IDistributedLockHandle>> TryAcquireHandleAsync(string resourceId, CancellationToken cancellationToken = default)

    Attempts to acquire a strongly typed distributed lock handle immediately without waiting.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

  • methodTryAcquireHandleAsync
    public async Task<Result<IDistributedLockHandle>> TryAcquireHandleAsync(string resourceId, TimeSpan timeout, CancellationToken cancellationToken = default)

    Attempts to acquire a strongly typed distributed lock handle within a maximum duration.

    resourceId: string
    The unique identifier of the resource to lock.
    timeout: TimeSpan
    The maximum duration to wait for the lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

class

MySqlLockOptions

Ensamblado: EricksonLopez.DistributedLock.MySql
public sealed class MySqlLockOptions

Specifies configuration options for the MySQL distributed lock provider.

Miembros (7)

  • propertyBackoffJitter
    public bool BackoffJitter { get; set; }

    Gets or sets a value indicating whether random jitter is added to retry intervals.

    Retained for backward compatibility. This property is unused because the database engine natively coordinates lock waiting on the server side.

  • propertyCommandTimeoutSeconds
    public int CommandTimeoutSeconds { get; set; }

    Gets or sets the command timeout in seconds for lock maintenance commands.

    The default value is 30 seconds.

  • propertyDatabaseScope
    public string? DatabaseScope { get; set; }

    Gets or sets an explicit namespace or tenant prefix prepended to the lock resource name.

  • propertyKeepaliveCadence
    public TimeSpan? KeepaliveCadence { get; set; }

    Gets or sets the cadence for sending keepalive heartbeat queries over held session connections.

    When set to `null`, keepalive heartbeats are disabled. Defaults to 10 seconds.

  • propertyMaxAcquisitionTimeoutSeconds
    public int MaxAcquisitionTimeoutSeconds { get; set; }

    Gets or sets the acquisition timeout chunk in seconds for blocking acquisition calls (AcquireHandleAsync). Prevents 68-year permanent hangs in MySQL metadata locks. The default value is 300 seconds (5 minutes).

  • propertyRetryInterval
    public TimeSpan RetryInterval { get; set; }

    Gets or sets the base polling interval when waiting for a lock with timeout.

    Retained for backward compatibility. This property is unused because the database engine natively coordinates lock waiting on the server side.

  • propertyScopeToDatabase
    public bool ScopeToDatabase { get; set; }

    Gets or sets a value indicating whether the connection's database catalog name should be prepended to the lock resource name to scope locks to the database in MySQL's global instance namespace. The default value is `false` for backward compatibility.

class

MySqlTransactionLockExtensions

Ensamblado: EricksonLopez.DistributedLock.MySql
public static class MySqlTransactionLockExtensions

Provides extension methods for acquiring MySQL locks within active database transactions.

Miembros (4)

  • methodAcquireInTransactionAsync
    public static Task<Result<IDistributedLockHandle>> AcquireInTransactionAsync(this DbTransaction transaction, string resourceId, ILogger logger, CancellationToken cancellationToken = default)

    Acquires an exclusive transaction-scoped lock on the specified `DbTransaction`, blocking until granted.

    transaction: this DbTransaction
    The active database transaction to bind the lock to.
    resourceId: string
    The unique identifier of the resource to lock.
    logger: ILogger
    The logger used for recording diagnostic and lifecycle events.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

    Exceptions: ArgumentNullException: `transaction` or `logger` is `null`; ArgumentException: `resourceId` is empty or contains only white space; InvalidOperationException: The connection associated with `transaction` is `null`

  • methodAcquireInTransactionAsync
    public static async Task<Result<IDistributedLockHandle>> AcquireInTransactionAsync(this IDbTransaction transaction, string resourceId, ILogger logger, CancellationToken cancellationToken = default)

    Acquires an exclusive transaction-scoped lock on the specified MySQL transaction, blocking until granted.

    transaction: this IDbTransaction
    The active database transaction to bind the lock to.
    resourceId: string
    The unique identifier of the resource to lock.
    logger: ILogger
    The logger used for recording diagnostic and lifecycle events.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

    Exceptions: ArgumentNullException: `transaction` or `logger` is `null`; ArgumentException: `resourceId` is empty or contains only white space; InvalidOperationException: The connection associated with `transaction` is `null`

  • methodTryAcquireInTransactionAsync
    public static Task<Result<IDistributedLockHandle>> TryAcquireInTransactionAsync(this DbTransaction transaction, string resourceId, ILogger logger, CancellationToken cancellationToken = default)

    Attempts to acquire an exclusive transaction-scoped lock on the specified `DbTransaction` immediately.

    transaction: this DbTransaction
    The active database transaction to bind the lock to.
    resourceId: string
    The unique identifier of the resource to lock.
    logger: ILogger
    The logger used for recording diagnostic and lifecycle events.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if the lock was acquired; otherwise, a failure with `DistributedLockErrors.LockAlreadyHeld`.

    Exceptions: ArgumentNullException: `transaction` or `logger` is `null`; ArgumentException: `resourceId` is empty or contains only white space; InvalidOperationException: The connection associated with `transaction` is `null`

  • methodTryAcquireInTransactionAsync
    public static async Task<Result<IDistributedLockHandle>> TryAcquireInTransactionAsync(this IDbTransaction transaction, string resourceId, ILogger logger, CancellationToken cancellationToken = default)

    Attempts to acquire an exclusive transaction-scoped lock on the specified MySQL transaction immediately.

    transaction: this IDbTransaction
    The active database transaction to bind the lock to.
    resourceId: string
    The unique identifier of the resource to lock.
    logger: ILogger
    The logger used for recording diagnostic and lifecycle events.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if the lock was acquired; otherwise, a failure with `DistributedLockErrors.LockAlreadyHeld`.

    Exceptions: ArgumentNullException: `transaction` or `logger` is `null`; ArgumentException: `resourceId` is empty or contains only white space; InvalidOperationException: The connection associated with `transaction` is `null`

EricksonLopez.DistributedLock.Oracle#

4
class

OracleDistributedLockHandle

Ensamblado: EricksonLopez.DistributedLock.Oracle
public sealed class OracleDistributedLockHandle : IDistributedLockHandle
Implementa: IDistributedLockHandle

Represents an active Oracle Database lock handle managed via DBMS_LOCK that releases the lock upon disposal.

Miembros (5)

  • constructorOracleDistributedLockHandle
    public OracleDistributedLockHandle(DbConnection connection, string lockHandle, string resourceId, ILogger logger, TimeSpan? keepaliveCadence = null, int commandTimeoutSeconds = 30)

    Initializes a new instance of the `OracleDistributedLockHandle` class with the specified connection and lock parameters.

    connection: DbConnection
    The underlying database connection holding the DBMS_LOCK allocation.
    lockHandle: string
    The unique handle string allocated by DBMS_LOCK.ALLOCATE_UNIQUE.
    resourceId: string
    The logical resource identifier requested by the caller.
    logger: ILogger
    The logger used for recording diagnostic and lifecycle events.
    keepaliveCadence: TimeSpan?
    The optional interval for heartbeat queries to detect dropped connections.
    commandTimeoutSeconds: int
    The command timeout in seconds for lock maintenance commands.

    Exceptions: ArgumentNullException: `connection`, `lockHandle`, `resourceId`, or `logger` is `null`

  • methodDisposeAsync
    public async ValueTask DisposeAsync()

    Inherits documentation from base type or interface.

  • propertyHandleLostToken
    public CancellationToken HandleLostToken { get; }

    Gets a cancellation token that is canceled if lock ownership is lost unexpectedly.

    Triggered by unexpected events such as connection drops, server failovers, or keepalive timeouts.

  • propertyLockId
    public long LockId { get; }

    Gets the 64-bit numerical identifier derived for this lock.

    This value is an identifier derived deterministically from `ResourceId`, not a monotonic fencing token. For fencing verification against stale writes, see `FencingToken`. Sentinel value: Adapter implementations (such as internal fallback handles) may return `0` as a sentinel value when no numeric lock identifier is applicable. Consumers that inspect `LockId` should treat `0` as an uninitialized or non-applicable identifier.

  • propertyResourceId
    public string ResourceId { get; }

    Gets the unique identifier of the resource associated with this lock.

class

OracleDistributedLockProvider

Ensamblado: EricksonLopez.DistributedLock.Oracle
public sealed class OracleDistributedLockProvider : IDistributedLockProvider
Implementa: IDistributedLockProvider

Provides distributed locks backed by Oracle Database's DBMS_LOCK package.

Miembros (9)

  • constructorOracleDistributedLockProvider
    public OracleDistributedLockProvider(Func<DbConnection> connectionFactory, ILogger<OracleDistributedLockProvider> logger, IOptions<OracleLockOptions> options)

    Initializes a new instance of the `OracleDistributedLockProvider` class configured via options snapshot.

    connectionFactory: Func<DbConnection>
    The delegate producing dedicated database connections per lock handle.
    logger: ILogger<OracleDistributedLockProvider>
    The logger used for recording diagnostic and lifecycle events.
    options: IOptions<OracleLockOptions>
    The configuration options accessor.

    Exceptions: ArgumentNullException: `connectionFactory` or `logger` is `null`

  • constructorOracleDistributedLockProvider
    public OracleDistributedLockProvider(Func<DbConnection> connectionFactory, ILogger<OracleDistributedLockProvider> logger, OracleLockOptions? options = null)

    Initializes a new instance of the `OracleDistributedLockProvider` class using a connection factory for dedicated sessions.

    connectionFactory: Func<DbConnection>
    The delegate producing dedicated database connections per lock handle.
    logger: ILogger<OracleDistributedLockProvider>
    The logger used for recording diagnostic and lifecycle events.
    options: OracleLockOptions?
    The configuration options for lock acquisition and keepalive.

    Exceptions: ArgumentNullException: `connectionFactory` or `logger` is `null`

  • constructorOracleDistributedLockProvider
    public OracleDistributedLockProvider(IDbConnection connection, ILogger<OracleDistributedLockProvider> logger, OracleLockOptions? options = null)

    Initializes a new instance of the `OracleDistributedLockProvider` class using an existing database connection.

    connection: IDbConnection
    The database connection used for ambient session locks.
    logger: ILogger<OracleDistributedLockProvider>
    The logger used for recording diagnostic and lifecycle events.
    options: OracleLockOptions?
    The configuration options for lock acquisition and keepalive.

    Exceptions: ArgumentNullException: `connection` or `logger` is `null`

  • methodAcquireAsync
    public async Task<Result<IAsyncDisposable>> AcquireAsync(string resourceId, CancellationToken cancellationToken = default)

    Acquires a distributed lock for the specified resource, blocking until the lock is granted.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if acquired; otherwise, the acquisition error.

    The default interface implementation delegates to `TryAcquireAsync(string, TimeSpan, CancellationToken)` with `Timeout.InfiniteTimeSpan`. Concrete implementations may override this method to use native engine blocking primitives.

  • methodAcquireHandleAsync
    public async Task<Result<IDistributedLockHandle>> AcquireHandleAsync(string resourceId, CancellationToken cancellationToken = default)

    Acquires a strongly typed distributed lock handle, blocking until the lock is granted.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

  • methodTryAcquireAsync
    public async Task<Result<IAsyncDisposable>> TryAcquireAsync(string resourceId, CancellationToken cancellationToken = default)

    Attempts to acquire a distributed lock for the specified resource immediately without waiting.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if the lock was acquired; otherwise, a failure with `DistributedLockErrors.LockAlreadyHeld`.

  • methodTryAcquireAsync
    public async Task<Result<IAsyncDisposable>> TryAcquireAsync(string resourceId, TimeSpan timeout, CancellationToken cancellationToken = default)

    Attempts to acquire a distributed lock for the specified resource within a maximum duration.

    resourceId: string
    The unique identifier of the resource to lock.
    timeout: TimeSpan
    The maximum duration to wait for the lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if the lock was acquired; otherwise, a failure with `DistributedLockErrors.Timeout`.

  • methodTryAcquireHandleAsync
    public async Task<Result<IDistributedLockHandle>> TryAcquireHandleAsync(string resourceId, CancellationToken cancellationToken = default)

    Attempts to acquire a strongly typed distributed lock handle immediately without waiting.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

  • methodTryAcquireHandleAsync
    public async Task<Result<IDistributedLockHandle>> TryAcquireHandleAsync(string resourceId, TimeSpan timeout, CancellationToken cancellationToken = default)

    Attempts to acquire a strongly typed distributed lock handle within a maximum duration.

    resourceId: string
    The unique identifier of the resource to lock.
    timeout: TimeSpan
    The maximum duration to wait for the lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

class

OracleLockOptions

Ensamblado: EricksonLopez.DistributedLock.Oracle
public sealed class OracleLockOptions

Specifies configuration options for the Oracle Database distributed lock provider using DBMS_LOCK.

Miembros (4)

  • propertyBackoffJitter
    public bool BackoffJitter { get; set; }

    Gets or sets a value indicating whether random jitter is added to retry intervals.

    Retained for backward compatibility. This property is unused because the database engine natively coordinates lock waiting on the server side.

  • propertyCommandTimeoutSeconds
    public int CommandTimeoutSeconds { get; set; }

    Gets or sets the command timeout in seconds for lock maintenance commands.

    The default value is 30 seconds.

  • propertyKeepaliveCadence
    public TimeSpan? KeepaliveCadence { get; set; }

    Gets or sets the cadence for sending keepalive heartbeat queries over held session connections.

    When set to `null`, keepalive heartbeats are disabled. Defaults to 10 seconds.

  • propertyRetryInterval
    public TimeSpan RetryInterval { get; set; }

    Gets or sets the base polling interval when waiting for a lock with timeout.

    Retained for backward compatibility. This property is unused because the database engine natively coordinates lock waiting on the server side.

class

OracleTransactionLockExtensions

Ensamblado: EricksonLopez.DistributedLock.Oracle
public static class OracleTransactionLockExtensions

Provides extension methods for acquiring Oracle DBMS_LOCK locks within active database transactions.

Miembros (4)

  • methodAcquireInTransactionAsync
    public static Task<Result<IDistributedLockHandle>> AcquireInTransactionAsync(this DbTransaction transaction, string resourceId, ILogger logger, CancellationToken cancellationToken = default)

    Acquires an exclusive transaction-scoped lock on the specified `DbTransaction`, blocking until granted.

    transaction: this DbTransaction
    The active database transaction to bind the lock to.
    resourceId: string
    The unique identifier of the resource to lock.
    logger: ILogger
    The logger used for recording diagnostic and lifecycle events.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

    Exceptions: ArgumentNullException: `transaction` or `logger` is `null`; ArgumentException: `resourceId` is empty or contains only white space; InvalidOperationException: The connection associated with `transaction` is `null`

  • methodAcquireInTransactionAsync
    public static async Task<Result<IDistributedLockHandle>> AcquireInTransactionAsync(this IDbTransaction transaction, string resourceId, ILogger logger, CancellationToken cancellationToken = default)

    Acquires an exclusive transaction-scoped lock on the specified Oracle transaction, blocking until granted.

    transaction: this IDbTransaction
    The active database transaction to bind the lock to.
    resourceId: string
    The unique identifier of the resource to lock.
    logger: ILogger
    The logger used for recording diagnostic and lifecycle events.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

    Exceptions: ArgumentNullException: `transaction` or `logger` is `null`; ArgumentException: `resourceId` is empty or contains only white space; InvalidOperationException: The connection associated with `transaction` is `null`

  • methodTryAcquireInTransactionAsync
    public static Task<Result<IDistributedLockHandle>> TryAcquireInTransactionAsync(this DbTransaction transaction, string resourceId, ILogger logger, CancellationToken cancellationToken = default)

    Attempts to acquire an exclusive transaction-scoped lock on the specified `DbTransaction` immediately.

    transaction: this DbTransaction
    The active database transaction to bind the lock to.
    resourceId: string
    The unique identifier of the resource to lock.
    logger: ILogger
    The logger used for recording diagnostic and lifecycle events.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if the lock was acquired; otherwise, a failure with `DistributedLockErrors.LockAlreadyHeld`.

    Exceptions: ArgumentNullException: `transaction` or `logger` is `null`; ArgumentException: `resourceId` is empty or contains only white space; InvalidOperationException: The connection associated with `transaction` is `null`

  • methodTryAcquireInTransactionAsync
    public static async Task<Result<IDistributedLockHandle>> TryAcquireInTransactionAsync(this IDbTransaction transaction, string resourceId, ILogger logger, CancellationToken cancellationToken = default)

    Attempts to acquire an exclusive transaction-scoped lock on the specified Oracle transaction immediately.

    transaction: this IDbTransaction
    The active database transaction to bind the lock to.
    resourceId: string
    The unique identifier of the resource to lock.
    logger: ILogger
    The logger used for recording diagnostic and lifecycle events.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if the lock was acquired; otherwise, a failure with `DistributedLockErrors.LockAlreadyHeld`.

    Exceptions: ArgumentNullException: `transaction` or `logger` is `null`; ArgumentException: `resourceId` is empty or contains only white space; InvalidOperationException: The connection associated with `transaction` is `null`

EricksonLopez.DistributedLock.PostgreSql#

6
class

NoOpAsyncDisposable

Ensamblado: EricksonLopez.DistributedLock.PostgreSql
public sealed class NoOpAsyncDisposable(string resourceId, long lockId) : IDistributedLockHandle
Implementa: IDistributedLockHandle

Represents a no-operation disposable handle returned for transaction-bound locks. Transaction-bound locks are released automatically when the transaction commits or rolls back.

Notas:

Because transaction-bound locks do not hold a dedicated connection, there is no keepalive heartbeat and no mechanism to signal premature lock loss. Consequently, `HandleLostToken` returns `CancellationToken.None`. Consumers should link cancellation to the transaction lifetime. Implementation note: Although this class is `public`, it is an implementation detail of `PostgresDistributedLockProvider`. Consumers should interact with this handle through the `IDistributedLockHandle` interface, not by constructing it directly.

Miembros (5)

  • constructorNoOpAsyncDisposable
    public NoOpAsyncDisposable(string resourceId = "", long lockId = 0)

    Initializes a new instance of NoOpAsyncDisposable.

    resourceId: string
    The resource identifier string for the lock, used for identification purposes.
    lockId: long
    The 64-bit numeric lock identifier associated with this handle; typically derived from `resourceId` by the caller using `PostgresDistributedLockProvider.GenerateLockId`.

    Because transaction-bound locks do not hold a dedicated connection, there is no keepalive heartbeat and no mechanism to signal premature lock loss. Consequently, `NoOpAsyncDisposable.HandleLostToken` returns `CancellationToken.None`. Consumers should link cancellation to the transaction lifetime. Implementation note: Although this class is `public`, it is an implementation detail of `PostgresDistributedLockProvider`. Consumers should interact with this handle through the `IDistributedLockHandle` interface, not by constructing it directly.

  • methodDisposeAsync
    public ValueTask DisposeAsync()

    Inherits documentation from base type or interface.

  • propertyHandleLostToken
    public CancellationToken HandleLostToken { get; }

    Gets a cancellation token that is never canceled for transaction-scoped locks.

    Transaction-bound locks do not use a keepalive heartbeat; their lifecycle is governed entirely by the enclosing database transaction. This token is never signaled.

  • propertyLockId
    public long LockId { get; }

    Gets the 64-bit numerical identifier derived for this lock.

    This value is an identifier derived deterministically from `ResourceId`, not a monotonic fencing token. For fencing verification against stale writes, see `FencingToken`. Sentinel value: Adapter implementations (such as internal fallback handles) may return `0` as a sentinel value when no numeric lock identifier is applicable. Consumers that inspect `LockId` should treat `0` as an uninitialized or non-applicable identifier.

  • propertyResourceId
    public string ResourceId { get; }

    Gets the unique identifier of the resource associated with this lock.

class

PostgresAdvisoryLockHandle

Ensamblado: EricksonLopez.DistributedLock.PostgreSql
public sealed class PostgresAdvisoryLockHandle : IDistributedLockHandle
Implementa: IDistributedLockHandle

Represents a session-level PostgreSQL advisory lock handle that maintains heartbeats and releases the lock upon disposal.

Notas:

Implementation note: Although this class is `public`, it is an implementation detail of `PostgresDistributedLockProvider`. Consumers should interact with this handle exclusively through the `IDistributedLockHandle` interface. Direct instantiation by consumer code is not a supported use case.

Miembros (5)

  • constructorPostgresAdvisoryLockHandle
    public PostgresAdvisoryLockHandle(DbConnection connection, long lockId, string resourceId, ILogger logger, TimeSpan keepaliveCadence = default, int? commandTimeoutSeconds = null)

    Initializes a new instance of the `PostgresAdvisoryLockHandle` class with the specified connection and lock parameters.

    connection: DbConnection
    The dedicated database connection holding the session lock.
    lockId: long
    The 64-bit numerical identifier of the advisory lock.
    resourceId: string
    The logical resource identifier requested by the caller.
    logger: ILogger
    The logger used for recording diagnostic and lifecycle events.
    keepaliveCadence: TimeSpan
    The interval for periodic heartbeat queries to detect connection termination.
    commandTimeoutSeconds: int?
    The command timeout in seconds for lock maintenance commands.

    Exceptions: ArgumentNullException: `connection`, `resourceId`, or `logger` is `null`

  • methodDisposeAsync
    public async ValueTask DisposeAsync()

    Inherits documentation from base type or interface.

  • propertyHandleLostToken
    public CancellationToken HandleLostToken { get; }

    Gets a cancellation token that is canceled if lock ownership is lost unexpectedly.

    Triggered by unexpected events such as connection drops, server failovers, or keepalive timeouts.

  • propertyLockId
    public long LockId { get; }

    Gets the 64-bit numerical identifier derived for this lock.

    This value is an identifier derived deterministically from `ResourceId`, not a monotonic fencing token. For fencing verification against stale writes, see `FencingToken`. Sentinel value: Adapter implementations (such as internal fallback handles) may return `0` as a sentinel value when no numeric lock identifier is applicable. Consumers that inspect `LockId` should treat `0` as an uninitialized or non-applicable identifier.

  • propertyResourceId
    public string ResourceId { get; }

    Gets the unique identifier of the resource associated with this lock.

class

PostgresAdvisoryTransactionLock

Ensamblado: EricksonLopez.DistributedLock.PostgreSql
public static class PostgresAdvisoryTransactionLock

Provides connection-pool-safe, transaction-scoped PostgreSQL advisory locks (`pg_try_advisory_xact_lock` and `pg_advisory_xact_lock`) bound strictly to an existing `DbConnection` and `DbTransaction` without opening secondary connections or leaking session locks.

Miembros (3)

  • methodComputeLockKey
    public static long ComputeLockKey(string resourceKey)

    Computes a deterministic 64-bit signed advisory lock key from `resourceKey` using the first 8 big-endian bytes of SHA-256.

    resourceKey: string
    The non-empty logical lock resource key.

    Retorna: The deterministic 64-bit PostgreSQL advisory lock key.

  • methodTryAcquireAsync
    public static async Task<Result<bool>> TryAcquireAsync(DbConnection connection, DbTransaction transaction, string resourceKey, CancellationToken cancellationToken = default)

    Attempts a non-blocking `pg_try_advisory_xact_lock(@LockId)` on `connection` inside `transaction`. The lock is automatically released by PostgreSQL when `transaction` commits or rolls back.

    connection: DbConnection
    The open database connection.
    transaction: DbTransaction
    The mandatory active transaction owning the lock.
    resourceKey: string
    The logical resource key to lock.
    cancellationToken: CancellationToken
    A token to cancel the asynchronous operation.

    Retorna: `Result.Success(true)` when acquired, `Result.Success(false)` when held by another transaction, or an error on deadlock/cancellation.

  • methodTryAcquireHandleAsync
    public static Task<Result<IDistributedLockHandle>> TryAcquireHandleAsync(DbTransaction transaction, string resourceKey, ILogger? logger = null, CancellationToken cancellationToken = default)

    Acquires a transaction-bound advisory lock handle delegating to `PostgresTransactionLockExtensions.TryAcquireInTransactionAsync`.

    transaction: DbTransaction
    resourceKey: string
    logger: ILogger?
    cancellationToken: CancellationToken
class

PostgresDistributedLockProvider

Ensamblado: EricksonLopez.DistributedLock.PostgreSql
public sealed class PostgresDistributedLockProvider : IDistributedLockProvider
Implementa: IDistributedLockProvider

Provides distributed locks backed by PostgreSQL advisory locking functions. Supports both transaction-bound locks and session-level locks with deterministic handle lifecycle.

Notas:

PgBouncer / Connection Pooler Incompatibility: Session-level advisory locks (`pg_advisory_lock`) are bound directly to the backend PostgreSQL server process (`backend_pid`). When using connection poolers like PgBouncer in `pool_mode = transaction` or `pool_mode = statement`, subsequent queries are multiplexed across different physical server processes, which can cause session locks to leak or become inaccessible from the original client connection. When operating behind PgBouncer with transaction-level pooling, always use transaction-scoped locks (`PostgresTransactionLockExtensions.TryAcquireInTransactionAsync(IDbTransaction, string, ILogger, CancellationToken)`) or connect to a dedicated pool configured with `pool_mode = session`.

Miembros (12)

  • constructorPostgresDistributedLockProvider
    public PostgresDistributedLockProvider(Func<DbConnection> connectionFactory, ILogger<PostgresDistributedLockProvider> logger, IOptions<PostgresLockOptions> options)

    Initializes a new instance of the `PostgresDistributedLockProvider` class configured via options snapshot.

    connectionFactory: Func<DbConnection>
    The delegate producing dedicated database connections per lock handle.
    logger: ILogger<PostgresDistributedLockProvider>
    The logger used for recording diagnostic and lifecycle events.
    options: IOptions<PostgresLockOptions>
    The configuration options accessor.

    Exceptions: ArgumentNullException: `connectionFactory` or `logger` is `null`

  • constructorPostgresDistributedLockProvider
    public PostgresDistributedLockProvider(Func<DbConnection> connectionFactory, ILogger<PostgresDistributedLockProvider> logger, PostgresLockOptions? options = null)

    Initializes a new instance of the `PostgresDistributedLockProvider` class using a connection factory for dedicated sessions.

    connectionFactory: Func<DbConnection>
    The delegate producing dedicated database connections per lock handle.
    logger: ILogger<PostgresDistributedLockProvider>
    The logger used for recording diagnostic and lifecycle events.
    options: PostgresLockOptions?
    The configuration options for lock acquisition and keepalive.

    Exceptions: ArgumentNullException: `connectionFactory` or `logger` is `null`

  • constructorPostgresDistributedLockProvider
    public PostgresDistributedLockProvider(IDbTransaction transaction, ILogger<PostgresDistributedLockProvider> logger, PostgresLockOptions? options = null)

    Initializes a new instance of the `PostgresDistributedLockProvider` class using an active database transaction for transaction-bound locks.

    transaction: IDbTransaction
    The active database transaction to which advisory locks will be bound.
    logger: ILogger<PostgresDistributedLockProvider>
    The logger used for recording diagnostic and lifecycle events.
    options: PostgresLockOptions?
    The configuration options for lock acquisition and keepalive.

    Exceptions: ArgumentNullException: `transaction` or `logger` is `null`; ArgumentException: The connection associated with `transaction` is `null` or closed

  • methodAcquireAsync
    public async Task<Result<IAsyncDisposable>> AcquireAsync(string resourceId, CancellationToken cancellationToken = default)

    Acquires a distributed lock for the specified resource, blocking until the lock is granted.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if acquired; otherwise, the acquisition error.

    The default interface implementation delegates to `TryAcquireAsync(string, TimeSpan, CancellationToken)` with `Timeout.InfiniteTimeSpan`. Concrete implementations may override this method to use native engine blocking primitives.

  • methodAcquireAsync
    public async Task<Result<IAsyncDisposable>> AcquireAsync(string resourceId, TimeSpan timeout, CancellationToken cancellationToken = default)

    Acquires a distributed lock for the specified resource, blocking until granted or timeout expires.

    resourceId: string
    The unique identifier of the resource to lock.
    timeout: TimeSpan
    The maximum duration to wait for the lock. Pass `Timeout.InfiniteTimeSpan` for native blocking.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if acquired; otherwise, the acquisition error.

    Branching behavior of this PostgreSQL-specific override: - When `timeout` is `Timeout.InfiniteTimeSpan`: delegates directly to `AcquireAsync(string, CancellationToken)`, which issues `SELECT pg_advisory_lock(@LockId);` — a native server-side blocking call that suspends until the lock is granted. - When `timeout` is finite: delegates to `TryAcquireAsync(string, TimeSpan, CancellationToken)`, which uses jittered exponential polling (`PostgresLockOptions.JitterRatio`) until the deadline elapses or the lock is granted.

  • methodAcquireHandleAsync
    public async Task<Result<IDistributedLockHandle>> AcquireHandleAsync(string resourceId, CancellationToken cancellationToken = default)

    Inherits documentation from `IDistributedLockProvider.AcquireHandleAsync(string, CancellationToken)`.

    resourceId: string
    cancellationToken: CancellationToken
  • methodAcquireHandleAsync
    public async Task<Result<IDistributedLockHandle>> AcquireHandleAsync(string resourceId, TimeSpan timeout, CancellationToken cancellationToken = default)

    Inherits documentation from `IDistributedLockProvider.AcquireHandleAsync(string, TimeSpan, CancellationToken)`.

    resourceId: string
    timeout: TimeSpan
    cancellationToken: CancellationToken
  • methodGenerateLockId
    public static long GenerateLockId(string resourceId)

    Generates a deterministic 64-bit integer identifier from a string resource key.

    resourceId: string
    The unique identifier of the resource to convert.

    Retorna: A signed 64-bit integer suitable for PostgreSQL advisory lock functions.

    Uses SHA-256 to ensure uniform distribution across the entire signed 64-bit space. The first 8 bytes of the SHA-256 digest are read as a signed 64-bit integer using little-endian byte order (`BinaryPrimitives.ReadInt64LittleEndian`). This byte order is significant for interoperability: any external system computing the same lock identifier must apply the same endianness convention. Exceptions: ArgumentException: `resourceId` is empty or contains only white space

  • methodTryAcquireAsync
    public async Task<Result<IAsyncDisposable>> TryAcquireAsync(string resourceId, CancellationToken cancellationToken = default)

    Attempts to acquire a distributed lock for the specified resource immediately without waiting.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if the lock was acquired; otherwise, a failure with `DistributedLockErrors.LockAlreadyHeld`.

  • methodTryAcquireAsync
    public async Task<Result<IAsyncDisposable>> TryAcquireAsync(string resourceId, TimeSpan timeout, CancellationToken cancellationToken = default)

    Attempts to acquire a distributed lock for the specified resource within a maximum duration.

    resourceId: string
    The unique identifier of the resource to lock.
    timeout: TimeSpan
    The maximum duration to wait for the lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if the lock was acquired; otherwise, a failure with `DistributedLockErrors.Timeout`.

  • methodTryAcquireHandleAsync
    public async Task<Result<IDistributedLockHandle>> TryAcquireHandleAsync(string resourceId, CancellationToken cancellationToken = default)

    Inherits documentation from `IDistributedLockProvider.TryAcquireHandleAsync(string, CancellationToken)`.

    resourceId: string
    cancellationToken: CancellationToken
  • methodTryAcquireHandleAsync
    public async Task<Result<IDistributedLockHandle>> TryAcquireHandleAsync(string resourceId, TimeSpan timeout, CancellationToken cancellationToken = default)

    Inherits documentation from `IDistributedLockProvider.TryAcquireHandleAsync(string, TimeSpan, CancellationToken)`.

    resourceId: string
    timeout: TimeSpan
    cancellationToken: CancellationToken
class

PostgresLockOptions

Ensamblado: EricksonLopez.DistributedLock.PostgreSql
public sealed class PostgresLockOptions

Specifies configuration options for PostgreSQL distributed locks.

Miembros (5)

  • propertyCommandTimeoutSeconds
    public int? CommandTimeoutSeconds { get; set; }

    Gets or sets the command timeout in seconds for database advisory lock queries.

    A value of `null` disables command timeout (0) during indefinite blocking advisory lock queries.

  • propertyInitialPollingInterval
    public TimeSpan InitialPollingInterval { get; set; }

    Gets or sets the initial interval to wait between polling attempts when acquiring locks under contention.

    Defaults to 25 milliseconds.

  • propertyJitterRatio
    public double JitterRatio { get; set; }

    Gets or sets the jitter ratio applied to polling delays to prevent thundering herd contention.

    Must be between 0.0 (no jitter) and 1.0 (full jitter). Defaults to 0.25 (25% jitter).

  • propertyKeepaliveCadence
    public TimeSpan KeepaliveCadence { get; set; }

    Gets or sets the cadence for background keepalive ping operations on session-level locks.

    Set to `TimeSpan.Zero` or negative to disable keepalive heartbeats. Defaults to 30 seconds.

  • propertyMaxPollingInterval
    public TimeSpan MaxPollingInterval { get; set; }

    Gets or sets the maximum interval ceiling for polling attempts during exponential backoff.

    Defaults to 250 milliseconds.

class

PostgresTransactionLockExtensions

Ensamblado: EricksonLopez.DistributedLock.PostgreSql
public static class PostgresTransactionLockExtensions

Provides extension methods for acquiring transaction-bound PostgreSQL advisory locks attached to existing database transactions.

Miembros (2)

  • methodAcquireInTransactionAsync
    public static async Task<Result<IDistributedLockHandle>> AcquireInTransactionAsync(this IDbTransaction transaction, string resourceId, ILogger logger, CancellationToken cancellationToken = default)

    Acquires a PostgreSQL advisory lock bound directly to an active database transaction, waiting until the lock is granted. The lock is automatically released when the transaction is committed or rolled back.

    transaction: this IDbTransaction
    The active database transaction to which the lock will be bound.
    resourceId: string
    The unique identifier of the resource to lock.
    logger: ILogger
    The logger used to record diagnostic and telemetry information.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a successful `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, an error result containing `DistributedLockErrors.Canceled`.

    Exceptions: ArgumentNullException: `transaction` or `logger` is `null`; ArgumentException: `resourceId` is empty or contains only white space; InvalidOperationException: The connection associated with `transaction` is `null`

  • methodTryAcquireInTransactionAsync
    public static async Task<Result<IDistributedLockHandle>> TryAcquireInTransactionAsync(this IDbTransaction transaction, string resourceId, ILogger logger, CancellationToken cancellationToken = default)

    Attempts to acquire a PostgreSQL advisory lock bound directly to an active database transaction. The lock is automatically released when the transaction is committed or rolled back.

    transaction: this IDbTransaction
    The active database transaction to which the lock will be bound.
    resourceId: string
    The unique identifier of the resource to lock.
    logger: ILogger
    The logger used to record diagnostic and telemetry information.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a successful `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, an error result containing `DistributedLockErrors.LockAlreadyHeld` or `DistributedLockErrors.Canceled`.

    Exceptions: ArgumentNullException: `transaction` or `logger` is `null`; ArgumentException: `resourceId` is empty or contains only white space; InvalidOperationException: The connection associated with `transaction` is `null`

EricksonLopez.DistributedLock.Redis#

3
class

RedisDistributedLockHandle

Ensamblado: EricksonLopez.DistributedLock.Redis
public sealed class RedisDistributedLockHandle : IDistributedLockHandle
Implementa: IDistributedLockHandle

Represents an acquired distributed lock backed by Redis.

Notas:

Releases the acquired Redis lock when disposed. An optional keepalive background loop can periodically renew the lock lease until disposal.

Miembros (6)

  • constructorRedisDistributedLockHandle
    public RedisDistributedLockHandle(IDatabase database, RedisKey key, RedisValue lockValue, string resourceId, TimeSpan expiry, ILogger logger, TimeSpan? keepaliveCadence = null, long? fencingToken = null)

    Initializes a new instance of the `RedisDistributedLockHandle` class.

    database: IDatabase
    The Redis database instance used to manage the lock.
    key: RedisKey
    The Redis key representing the locked resource.
    lockValue: RedisValue
    The unique value identifying the lock ownership token.
    resourceId: string
    The unique identifier of the resource associated with the lock.
    expiry: TimeSpan
    The lease duration for the lock.
    logger: ILogger
    The logger used to record diagnostic and telemetry information.
    keepaliveCadence: TimeSpan?
    The cadence for renewing the lock lease, or `null` to disable keepalive renewal.
    fencingToken: long?
    The monotonic fencing token associated with this lock lease, if any.

    Exceptions: ArgumentNullException: `database`, `resourceId`, or `logger` is `null`

  • methodDisposeAsync
    public async ValueTask DisposeAsync()

    Inherits documentation from base type or interface.

  • propertyFencingToken
    public long? FencingToken { get; }

    Gets an optional monotonic fencing token associated with this lock acquisition.

    Enables downstream resource validation against stale split-brain writes. Returns `null` if the underlying locking engine does not support monotonic fencing tokens.

  • propertyHandleLostToken
    public CancellationToken HandleLostToken { get; }

    Gets a cancellation token that is canceled if lock ownership is lost unexpectedly.

    Triggered by unexpected events such as connection drops, server failovers, or keepalive timeouts.

  • propertyLockId
    public long LockId { get; }

    Gets the 64-bit numerical identifier derived for this lock.

    This value is an identifier derived deterministically from `ResourceId`, not a monotonic fencing token. For fencing verification against stale writes, see `FencingToken`. Sentinel value: Adapter implementations (such as internal fallback handles) may return `0` as a sentinel value when no numeric lock identifier is applicable. Consumers that inspect `LockId` should treat `0` as an uninitialized or non-applicable identifier.

  • propertyResourceId
    public string ResourceId { get; }

    Gets the unique identifier of the resource associated with this lock.

class

RedisDistributedLockProvider

Ensamblado: EricksonLopez.DistributedLock.Redis
public sealed class RedisDistributedLockProvider : IDistributedLockProvider
Implementa: IDistributedLockProvider

Provides distributed locking capabilities backed by Redis key-value storage.

Notas:

Redis Lease Expiration & GC Pause Warning: Redis distributed locks rely on TTL expiration (`SET NX PX`). If an application process experiences a prolonged garbage collection pause (STW GC) or network partition exceeding the lock lease duration (`RedisLockOptions.DefaultExpiry`), Redis will automatically expire the key, allowing another node to claim ownership while the original worker is still processing. To mitigate this risk, configure `RedisLockOptions.KeepaliveCadence` for automated background renewal, keep critical section operations brief, and link background processing to `IDistributedLockHandle.HandleLostToken`.

Miembros (8)

  • constructorRedisDistributedLockProvider
    public RedisDistributedLockProvider(IConnectionMultiplexer multiplexer, ILogger<RedisDistributedLockProvider> logger, IOptions<RedisLockOptions> options)

    Initializes a new instance of the `RedisDistributedLockProvider` class configured via `IOptions<TOptions>`.

    multiplexer: IConnectionMultiplexer
    The connection multiplexer used to communicate with Redis.
    logger: ILogger<RedisDistributedLockProvider>
    The logger used to record diagnostic and telemetry information.
    options: IOptions<RedisLockOptions>
    The options accessor containing provider configuration options.

    Exceptions: ArgumentNullException: `multiplexer` or `logger` is `null`

  • constructorRedisDistributedLockProvider
    public RedisDistributedLockProvider(IConnectionMultiplexer multiplexer, ILogger<RedisDistributedLockProvider> logger, RedisLockOptions? options = null)

    Initializes a new instance of the `RedisDistributedLockProvider` class.

    multiplexer: IConnectionMultiplexer
    The connection multiplexer used to communicate with Redis.
    logger: ILogger<RedisDistributedLockProvider>
    The logger used to record diagnostic and telemetry information.
    options: RedisLockOptions?
    The configuration options for this provider, or `null` to use default options.

    Exceptions: ArgumentNullException: `multiplexer` or `logger` is `null`

  • methodAcquireAsync
    public async Task<Result<IAsyncDisposable>> AcquireAsync(string resourceId, CancellationToken cancellationToken = default)

    Acquires a distributed lock for the specified resource, blocking until the lock is granted.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if acquired; otherwise, the acquisition error.

    The default interface implementation delegates to `TryAcquireAsync(string, TimeSpan, CancellationToken)` with `Timeout.InfiniteTimeSpan`. Concrete implementations may override this method to use native engine blocking primitives.

  • methodAcquireHandleAsync
    public async Task<Result<IDistributedLockHandle>> AcquireHandleAsync(string resourceId, CancellationToken cancellationToken = default)

    Acquires a strongly typed distributed lock handle, blocking until the lock is granted.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

  • methodTryAcquireAsync
    public async Task<Result<IAsyncDisposable>> TryAcquireAsync(string resourceId, CancellationToken cancellationToken = default)

    Attempts to acquire a distributed lock for the specified resource immediately without waiting.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if the lock was acquired; otherwise, a failure with `DistributedLockErrors.LockAlreadyHeld`.

  • methodTryAcquireAsync
    public async Task<Result<IAsyncDisposable>> TryAcquireAsync(string resourceId, TimeSpan timeout, CancellationToken cancellationToken = default)

    Attempts to acquire a distributed lock for the specified resource within a maximum duration.

    resourceId: string
    The unique identifier of the resource to lock.
    timeout: TimeSpan
    The maximum duration to wait for the lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if the lock was acquired; otherwise, a failure with `DistributedLockErrors.Timeout`.

  • methodTryAcquireHandleAsync
    public async Task<Result<IDistributedLockHandle>> TryAcquireHandleAsync(string resourceId, CancellationToken cancellationToken = default)

    Attempts to acquire a strongly typed distributed lock handle immediately without waiting.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

  • methodTryAcquireHandleAsync
    public async Task<Result<IDistributedLockHandle>> TryAcquireHandleAsync(string resourceId, TimeSpan timeout, CancellationToken cancellationToken = default)

    Attempts to acquire a strongly typed distributed lock handle within a maximum duration.

    resourceId: string
    The unique identifier of the resource to lock.
    timeout: TimeSpan
    The maximum duration to wait for the lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

class

RedisLockOptions

Ensamblado: EricksonLopez.DistributedLock.Redis
public sealed class RedisLockOptions

Represents configuration options for `RedisDistributedLockProvider`.

Miembros (5)

  • propertyBackoffJitter
    public bool BackoffJitter { get; set; }

    Gets or sets a value indicating whether random jitter is added to retry intervals. The default value is `true`.

  • propertyDefaultExpiry
    public TimeSpan DefaultExpiry { get; set; }

    Gets or sets the default lease duration for acquired locks. The default value is 30 seconds.

  • propertyKeepaliveCadence
    public TimeSpan? KeepaliveCadence { get; set; }

    Gets or sets the cadence for renewing lock leases before expiration. The default value is 10 seconds.

  • propertyKeyPrefix
    public string KeyPrefix { get; set; }

    Gets or sets the key prefix prepended to resource identifiers in Redis. The default value is `"lock:"`.

  • propertyRetryInterval
    public TimeSpan RetryInterval { get; set; }

    Gets or sets the base polling interval when waiting for a lock with timeout. The default value is 50 milliseconds.

EricksonLopez.DistributedLock.SqlServer#

4
class

SqlServerDistributedLockHandle

Ensamblado: EricksonLopez.DistributedLock.SqlServer
public sealed class SqlServerDistributedLockHandle : IDistributedLockHandle
Implementa: IDistributedLockHandle

Represents an acquired distributed lock backed by a Microsoft SQL Server application lock.

Notas:

Releases the acquired SQL Server application lock and closes the underlying database connection upon disposal.

Miembros (5)

  • constructorSqlServerDistributedLockHandle
    public SqlServerDistributedLockHandle(DbConnection connection, string lockResource, string resourceId, string lockOwner, ILogger logger, TimeSpan? keepaliveCadence = null, int commandTimeoutSeconds = 30)

    Initializes a new instance of the `SqlServerDistributedLockHandle` class.

    connection: DbConnection
    The database connection dedicated to holding the application lock.
    lockResource: string
    The formatted lock resource name used in SQL Server.
    resourceId: string
    The unique identifier of the resource associated with the lock.
    lockOwner: string
    The lock owner mode, typically `"Session"` or `"Transaction"`.
    logger: ILogger
    The logger used to record diagnostic and telemetry information.
    keepaliveCadence: TimeSpan?
    The cadence for sending keepalive heartbeat queries, or `null` to disable keepalive.
    commandTimeoutSeconds: int
    The command timeout in seconds for lock queries.

    Exceptions: ArgumentNullException: `connection`, `lockResource`, `resourceId`, `lockOwner`, or `logger` is `null`

  • methodDisposeAsync
    public async ValueTask DisposeAsync()

    Inherits documentation from base type or interface.

  • propertyHandleLostToken
    public CancellationToken HandleLostToken { get; }

    Gets a cancellation token that is canceled if lock ownership is lost unexpectedly.

    Triggered by unexpected events such as connection drops, server failovers, or keepalive timeouts.

  • propertyLockId
    public long LockId { get; }

    Gets the 64-bit numerical identifier derived for this lock.

    This value is an identifier derived deterministically from `ResourceId`, not a monotonic fencing token. For fencing verification against stale writes, see `FencingToken`. Sentinel value: Adapter implementations (such as internal fallback handles) may return `0` as a sentinel value when no numeric lock identifier is applicable. Consumers that inspect `LockId` should treat `0` as an uninitialized or non-applicable identifier.

  • propertyResourceId
    public string ResourceId { get; }

    Gets the unique identifier of the resource associated with this lock.

class

SqlServerDistributedLockProvider

Ensamblado: EricksonLopez.DistributedLock.SqlServer
public sealed class SqlServerDistributedLockProvider : IDistributedLockProvider
Implementa: IDistributedLockProvider

Provides distributed locking capabilities backed by Microsoft SQL Server application locks.

Notas:

Database Collation Sensitivity: Resource key comparisons in SQL Server are collation-sensitive. On case-insensitive databases (such as `SQL_Latin1_General_CP1_CI_AS`), resource keys differing only by casing resolve to the same underlying application lock resource.

Miembros (9)

  • constructorSqlServerDistributedLockProvider
    public SqlServerDistributedLockProvider(Func<DbConnection> connectionFactory, ILogger<SqlServerDistributedLockProvider> logger, IOptions<SqlServerLockOptions> options)

    Initializes a new instance of the `SqlServerDistributedLockProvider` class configured via `IOptions<TOptions>`.

    connectionFactory: Func<DbConnection>
    The factory delegate that creates new database connections.
    logger: ILogger<SqlServerDistributedLockProvider>
    The logger used to record diagnostic and telemetry information.
    options: IOptions<SqlServerLockOptions>
    The options accessor containing provider configuration options.

    Exceptions: ArgumentNullException: `connectionFactory` or `logger` is `null`

  • constructorSqlServerDistributedLockProvider
    public SqlServerDistributedLockProvider(Func<DbConnection> connectionFactory, ILogger<SqlServerDistributedLockProvider> logger, SqlServerLockOptions? options = null)

    Initializes a new instance of the `SqlServerDistributedLockProvider` class using a connection factory delegate.

    connectionFactory: Func<DbConnection>
    The factory delegate that creates new database connections.
    logger: ILogger<SqlServerDistributedLockProvider>
    The logger used to record diagnostic and telemetry information.
    options: SqlServerLockOptions?
    The configuration options for this provider, or `null` to use default options.

    Exceptions: ArgumentNullException: `connectionFactory` or `logger` is `null`

  • constructorSqlServerDistributedLockProvider
    public SqlServerDistributedLockProvider(IDbConnection connection, ILogger<SqlServerDistributedLockProvider> logger, SqlServerLockOptions? options = null)

    Initializes a new instance of the `SqlServerDistributedLockProvider` class using an existing database connection.

    connection: IDbConnection
    The database connection used for acquiring application locks.
    logger: ILogger<SqlServerDistributedLockProvider>
    The logger used to record diagnostic and telemetry information.
    options: SqlServerLockOptions?
    The configuration options for this provider, or `null` to use default options.

    Exceptions: ArgumentNullException: `connection` or `logger` is `null`

  • methodAcquireAsync
    public async Task<Result<IAsyncDisposable>> AcquireAsync(string resourceId, CancellationToken cancellationToken = default)

    Acquires a distributed lock for the specified resource, blocking until the lock is granted.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if acquired; otherwise, the acquisition error.

    The default interface implementation delegates to `TryAcquireAsync(string, TimeSpan, CancellationToken)` with `Timeout.InfiniteTimeSpan`. Concrete implementations may override this method to use native engine blocking primitives.

  • methodAcquireHandleAsync
    public async Task<Result<IDistributedLockHandle>> AcquireHandleAsync(string resourceId, CancellationToken cancellationToken = default)

    Acquires a strongly typed distributed lock handle, blocking until the lock is granted.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

  • methodTryAcquireAsync
    public async Task<Result<IAsyncDisposable>> TryAcquireAsync(string resourceId, CancellationToken cancellationToken = default)

    Attempts to acquire a distributed lock for the specified resource immediately without waiting.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if the lock was acquired; otherwise, a failure with `DistributedLockErrors.LockAlreadyHeld`.

  • methodTryAcquireAsync
    public async Task<Result<IAsyncDisposable>> TryAcquireAsync(string resourceId, TimeSpan timeout, CancellationToken cancellationToken = default)

    Attempts to acquire a distributed lock for the specified resource within a maximum duration.

    resourceId: string
    The unique identifier of the resource to lock.
    timeout: TimeSpan
    The maximum duration to wait for the lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if the lock was acquired; otherwise, a failure with `DistributedLockErrors.Timeout`.

  • methodTryAcquireHandleAsync
    public async Task<Result<IDistributedLockHandle>> TryAcquireHandleAsync(string resourceId, CancellationToken cancellationToken = default)

    Attempts to acquire a strongly typed distributed lock handle immediately without waiting.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

  • methodTryAcquireHandleAsync
    public async Task<Result<IDistributedLockHandle>> TryAcquireHandleAsync(string resourceId, TimeSpan timeout, CancellationToken cancellationToken = default)

    Attempts to acquire a strongly typed distributed lock handle within a maximum duration.

    resourceId: string
    The unique identifier of the resource to lock.
    timeout: TimeSpan
    The maximum duration to wait for the lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

class

SqlServerLockOptions

Ensamblado: EricksonLopez.DistributedLock.SqlServer
public sealed class SqlServerLockOptions

Represents configuration options for `SqlServerDistributedLockProvider`.

Miembros (5)

  • propertyBackoffJitter
    public bool BackoffJitter { get; set; }

    Gets or sets a value indicating whether random jitter is added to retry intervals.

    Retained for backward compatibility. This property is unused because the database engine natively coordinates lock waiting on the server side.

  • propertyCommandTimeoutSeconds
    public int CommandTimeoutSeconds { get; set; }

    Gets or sets the command timeout in seconds for advisory lock queries. The default value is 30 seconds.

  • propertyKeepaliveCadence
    public TimeSpan? KeepaliveCadence { get; set; }

    Gets or sets the cadence for sending keepalive heartbeat queries over held session connections. When `null`, keepalives are disabled. The default value is 10 seconds.

  • propertyNormalizeCase
    public bool NormalizeCase { get; set; }

    Gets or sets a value indicating whether resource keys should be normalized to uppercase invariant prior to lock acquisition to guarantee deterministic matching under case-insensitive (CI) database collations. The default value is `false` to preserve raw key identifiers.

  • propertyRetryInterval
    public TimeSpan RetryInterval { get; set; }

    Gets or sets the base polling interval when waiting for a lock with timeout.

    Retained for backward compatibility. This property is unused because the database engine natively coordinates lock waiting on the server side.

class

SqlServerTransactionLockExtensions

Ensamblado: EricksonLopez.DistributedLock.SqlServer
public static class SqlServerTransactionLockExtensions

Provides extension methods for acquiring transaction-bound SQL Server application locks within active database transactions.

Miembros (4)

  • methodAcquireInTransactionAsync
    public static Task<Result<IDistributedLockHandle>> AcquireInTransactionAsync(this DbTransaction transaction, string resourceId, ILogger logger, CancellationToken cancellationToken = default)

    Acquires an exclusive transaction-scoped lock bound to an active `DbTransaction`, waiting until the lock is granted.

    transaction: this DbTransaction
    The active database transaction to which the lock will be bound.
    resourceId: string
    The unique identifier of the resource to lock.
    logger: ILogger
    The logger used to record diagnostic and telemetry information.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a successful `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, an error result containing `DistributedLockErrors.LockAlreadyHeld`.

    Exceptions: ArgumentNullException: `transaction` or `logger` is `null`; ArgumentException: `resourceId` is empty or contains only white space; InvalidOperationException: The connection associated with `transaction` is `null`

  • methodAcquireInTransactionAsync
    public static async Task<Result<IDistributedLockHandle>> AcquireInTransactionAsync(this IDbTransaction transaction, string resourceId, ILogger logger, CancellationToken cancellationToken = default)

    Acquires an exclusive transaction-scoped lock bound to an active `IDbTransaction`, waiting until the lock is granted.

    transaction: this IDbTransaction
    The active database transaction to which the lock will be bound.
    resourceId: string
    The unique identifier of the resource to lock.
    logger: ILogger
    The logger used to record diagnostic and telemetry information.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a successful `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, an error result containing `DistributedLockErrors.LockAlreadyHeld`.

    Exceptions: ArgumentNullException: `transaction` or `logger` is `null`; ArgumentException: `resourceId` is empty or contains only white space; InvalidOperationException: The connection associated with `transaction` is `null`

  • methodTryAcquireInTransactionAsync
    public static Task<Result<IDistributedLockHandle>> TryAcquireInTransactionAsync(this DbTransaction transaction, string resourceId, ILogger logger, CancellationToken cancellationToken = default)

    Attempts to acquire an exclusive transaction-scoped lock bound to an active `DbTransaction`.

    transaction: this DbTransaction
    The active database transaction to which the lock will be bound.
    resourceId: string
    The unique identifier of the resource to lock.
    logger: ILogger
    The logger used to record diagnostic and telemetry information.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a successful `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, an error result containing `DistributedLockErrors.LockAlreadyHeld`.

    Exceptions: ArgumentNullException: `transaction` or `logger` is `null`; ArgumentException: `resourceId` is empty or contains only white space; InvalidOperationException: The connection associated with `transaction` is `null`

  • methodTryAcquireInTransactionAsync
    public static async Task<Result<IDistributedLockHandle>> TryAcquireInTransactionAsync(this IDbTransaction transaction, string resourceId, ILogger logger, CancellationToken cancellationToken = default)

    Attempts to acquire an exclusive transaction-scoped lock bound to an active `IDbTransaction`.

    transaction: this IDbTransaction
    The active database transaction to which the lock will be bound.
    resourceId: string
    The unique identifier of the resource to lock.
    logger: ILogger
    The logger used to record diagnostic and telemetry information.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a successful `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, an error result containing `DistributedLockErrors.LockAlreadyHeld`.

    Exceptions: ArgumentNullException: `transaction` or `logger` is `null`; ArgumentException: `resourceId` is empty or contains only white space; InvalidOperationException: The connection associated with `transaction` is `null`

EricksonLopez.DistributedLock.Sqlite#

4
class

SqliteDistributedLockHandle

Ensamblado: EricksonLopez.DistributedLock.Sqlite
public sealed class SqliteDistributedLockHandle : IDistributedLockHandle
Implementa: IDistributedLockHandle

Represents an acquired distributed lock backed by a SQLite database table.

Notas:

Releases the acquired SQLite lock record and closes the underlying database connection upon disposal.

Miembros (7)

  • constructorSqliteDistributedLockHandle
    public SqliteDistributedLockHandle(DbConnection connection, string resourceId, string ownerId, ILogger logger, int commandTimeoutSeconds = 30, long? fencingToken = null)

    Initializes a new instance of the `SqliteDistributedLockHandle` class.

    connection: DbConnection
    The database connection dedicated to holding the lock.
    resourceId: string
    The unique identifier of the resource associated with the lock.
    ownerId: string
    The unique identifier representing the lock owner.
    logger: ILogger
    The logger used to record diagnostic and telemetry information.
    commandTimeoutSeconds: int
    The command timeout in seconds for lock queries.
    fencingToken: long?
    An optional monotonic fencing token associated with the lock.

    Exceptions: ArgumentNullException: `connection`, `resourceId`, `ownerId`, or `logger` is `null`

  • constructorSqliteDistributedLockHandle
    public SqliteDistributedLockHandle(DbConnection connection, string resourceId, string ownerId, ILogger logger, TimeSpan lockTtl, TimeSpan? keepaliveCadence = null, int commandTimeoutSeconds = 30, long? fencingToken = null)

    Initializes a new instance of the `SqliteDistributedLockHandle` class with lease TTL and keepalive cadence.

    connection: DbConnection
    The database connection dedicated to holding the lock.
    resourceId: string
    The unique identifier of the resource associated with the lock.
    ownerId: string
    The unique identifier representing the lock owner.
    logger: ILogger
    The logger used to record diagnostic and telemetry information.
    lockTtl: TimeSpan
    The lease duration before the lock expires.
    keepaliveCadence: TimeSpan?
    The cadence for renewing the lock lease, or `null` to disable keepalive renewal.
    commandTimeoutSeconds: int
    The command timeout in seconds for lock queries.
    fencingToken: long?
    An optional monotonic fencing token associated with the lock.

    Exceptions: ArgumentNullException: `connection`, `resourceId`, `ownerId`, or `logger` is `null`

  • methodDisposeAsync
    public async ValueTask DisposeAsync()

    Inherits documentation from base type or interface.

  • propertyFencingToken
    public long? FencingToken { get; }

    Gets an optional monotonic fencing token associated with this lock acquisition.

    Enables downstream resource validation against stale split-brain writes. Returns `null` if the underlying locking engine does not support monotonic fencing tokens.

  • propertyHandleLostToken
    public CancellationToken HandleLostToken { get; }

    Gets a cancellation token that is canceled if lock ownership is lost unexpectedly.

    Triggered by unexpected events such as connection drops, server failovers, or keepalive timeouts.

  • propertyLockId
    public long LockId { get; }

    Gets the 64-bit numerical identifier derived for this lock.

    This value is an identifier derived deterministically from `ResourceId`, not a monotonic fencing token. For fencing verification against stale writes, see `FencingToken`. Sentinel value: Adapter implementations (such as internal fallback handles) may return `0` as a sentinel value when no numeric lock identifier is applicable. Consumers that inspect `LockId` should treat `0` as an uninitialized or non-applicable identifier.

  • propertyResourceId
    public string ResourceId { get; }

    Gets the unique identifier of the resource associated with this lock.

class

SqliteDistributedLockProvider

Ensamblado: EricksonLopez.DistributedLock.Sqlite
public sealed class SqliteDistributedLockProvider : IDistributedLockProvider, IDisposable
Implementa: IDisposable, IDistributedLockProvider

Provides distributed locking capabilities backed by a SQLite database lock table.

Miembros (10)

  • constructorSqliteDistributedLockProvider
    public SqliteDistributedLockProvider(Func<DbConnection> connectionFactory, ILogger<SqliteDistributedLockProvider> logger, IOptions<SqliteLockOptions> options)

    Initializes a new instance of the `SqliteDistributedLockProvider` class configured via `IOptions<TOptions>`.

    connectionFactory: Func<DbConnection>
    The factory delegate that creates new database connections.
    logger: ILogger<SqliteDistributedLockProvider>
    The logger used to record diagnostic and telemetry information.
    options: IOptions<SqliteLockOptions>
    The options accessor containing provider configuration options.

    Exceptions: ArgumentNullException: `connectionFactory` or `logger` is `null`

  • constructorSqliteDistributedLockProvider
    public SqliteDistributedLockProvider(Func<DbConnection> connectionFactory, ILogger<SqliteDistributedLockProvider> logger, SqliteLockOptions? options = null)

    Initializes a new instance of the `SqliteDistributedLockProvider` class using a connection factory delegate.

    connectionFactory: Func<DbConnection>
    The factory delegate that creates new database connections.
    logger: ILogger<SqliteDistributedLockProvider>
    The logger used to record diagnostic and telemetry information.
    options: SqliteLockOptions?
    The configuration options for this provider, or `null` to use default options.

    Exceptions: ArgumentNullException: `connectionFactory` or `logger` is `null`

  • constructorSqliteDistributedLockProvider
    public SqliteDistributedLockProvider(IDbConnection connection, ILogger<SqliteDistributedLockProvider> logger, SqliteLockOptions? options = null)

    Initializes a new instance of the `SqliteDistributedLockProvider` class using an existing database connection.

    connection: IDbConnection
    The database connection used to manage lock records.
    logger: ILogger<SqliteDistributedLockProvider>
    The logger used to record diagnostic and telemetry information.
    options: SqliteLockOptions?
    The configuration options for this provider, or `null` to use default options.

    Exceptions: ArgumentNullException: `connection` or `logger` is `null`

  • methodAcquireAsync
    public async Task<Result<IAsyncDisposable>> AcquireAsync(string resourceId, CancellationToken cancellationToken = default)

    Acquires a distributed lock for the specified resource, blocking until the lock is granted.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if acquired; otherwise, the acquisition error.

    The default interface implementation delegates to `TryAcquireAsync(string, TimeSpan, CancellationToken)` with `Timeout.InfiniteTimeSpan`. Concrete implementations may override this method to use native engine blocking primitives.

  • methodAcquireHandleAsync
    public async Task<Result<IDistributedLockHandle>> AcquireHandleAsync(string resourceId, CancellationToken cancellationToken = default)

    Acquires a strongly typed distributed lock handle, blocking until the lock is granted.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

  • methodDispose
    public void Dispose()

    Inherits documentation from base type or interface.

  • methodTryAcquireAsync
    public async Task<Result<IAsyncDisposable>> TryAcquireAsync(string resourceId, CancellationToken cancellationToken = default)

    Attempts to acquire a distributed lock for the specified resource immediately without waiting.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if the lock was acquired; otherwise, a failure with `DistributedLockErrors.LockAlreadyHeld`.

  • methodTryAcquireAsync
    public async Task<Result<IAsyncDisposable>> TryAcquireAsync(string resourceId, TimeSpan timeout, CancellationToken cancellationToken = default)

    Attempts to acquire a distributed lock for the specified resource within a maximum duration.

    resourceId: string
    The unique identifier of the resource to lock.
    timeout: TimeSpan
    The maximum duration to wait for the lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IAsyncDisposable` handle if the lock was acquired; otherwise, a failure with `DistributedLockErrors.Timeout`.

  • methodTryAcquireHandleAsync
    public async Task<Result<IDistributedLockHandle>> TryAcquireHandleAsync(string resourceId, CancellationToken cancellationToken = default)

    Attempts to acquire a strongly typed distributed lock handle immediately without waiting.

    resourceId: string
    The unique identifier of the resource to lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

  • methodTryAcquireHandleAsync
    public async Task<Result<IDistributedLockHandle>> TryAcquireHandleAsync(string resourceId, TimeSpan timeout, CancellationToken cancellationToken = default)

    Attempts to acquire a strongly typed distributed lock handle within a maximum duration.

    resourceId: string
    The unique identifier of the resource to lock.
    timeout: TimeSpan
    The maximum duration to wait for the lock.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, the acquisition error.

class

SqliteLockOptions

Ensamblado: EricksonLopez.DistributedLock.Sqlite
public sealed class SqliteLockOptions

Represents configuration options for `SqliteDistributedLockProvider`.

Miembros (5)

  • propertyBackoffJitter
    public bool BackoffJitter { get; set; }

    Gets or sets a value indicating whether random jitter is added to retry intervals. The default value is `true`.

  • propertyCommandTimeoutSeconds
    public int CommandTimeoutSeconds { get; set; }

    Gets or sets the command timeout in seconds for lock queries. The default value is 30 seconds.

  • propertyKeepaliveCadence
    public TimeSpan? KeepaliveCadence { get; set; }

    Gets or sets the cadence for background renewal of the lock lease. When `null`, defaults to one-third of `LockTtl`. The default value is 20 seconds.

  • propertyLockTtl
    public TimeSpan LockTtl { get; set; }

    Gets or sets the lock lease time-to-live duration. Locks exceeding this duration without renewal or release are considered orphaned and eligible for reclamation. The default value is 60 seconds.

  • propertyRetryInterval
    public TimeSpan RetryInterval { get; set; }

    Gets or sets the base polling interval when waiting for a lock with timeout. The default value is 50 milliseconds.

class

SqliteTransactionLockExtensions

Ensamblado: EricksonLopez.DistributedLock.Sqlite
public static class SqliteTransactionLockExtensions

Provides extension methods for acquiring transaction-bound SQLite locks within active database transactions.

Miembros (4)

  • methodAcquireInTransactionAsync
    public static Task<Result<IDistributedLockHandle>> AcquireInTransactionAsync(this DbTransaction transaction, string resourceId, ILogger logger, CancellationToken cancellationToken = default)

    Acquires an exclusive lock bound directly to an active `DbTransaction`, waiting until the lock is granted.

    transaction: this DbTransaction
    The active database transaction to which the lock will be bound.
    resourceId: string
    The unique identifier of the resource to lock.
    logger: ILogger
    The logger used to record diagnostic and telemetry information.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a successful `Result<T>` with an `IDistributedLockHandle`.

    Exceptions: ArgumentNullException: `transaction` or `logger` is `null`; ArgumentException: `resourceId` is empty or contains only white space; InvalidOperationException: The connection associated with `transaction` is `null`; OperationCanceledException: The operation was canceled via `cancellationToken`

  • methodAcquireInTransactionAsync
    public static async Task<Result<IDistributedLockHandle>> AcquireInTransactionAsync(this IDbTransaction transaction, string resourceId, ILogger logger, CancellationToken cancellationToken = default)

    Acquires an exclusive lock bound directly to an active `IDbTransaction`, waiting until the lock is granted.

    transaction: this IDbTransaction
    The active database transaction to which the lock will be bound.
    resourceId: string
    The unique identifier of the resource to lock.
    logger: ILogger
    The logger used to record diagnostic and telemetry information.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a successful `Result<T>` with an `IDistributedLockHandle`.

    Exceptions: ArgumentNullException: `transaction` or `logger` is `null`; ArgumentException: `resourceId` is empty or contains only white space; InvalidOperationException: The connection associated with `transaction` is `null`; OperationCanceledException: The operation was canceled via `cancellationToken`

  • methodTryAcquireInTransactionAsync
    public static Task<Result<IDistributedLockHandle>> TryAcquireInTransactionAsync(this DbTransaction transaction, string resourceId, ILogger logger, CancellationToken cancellationToken = default)

    Attempts to acquire an exclusive lock bound directly to an active `DbTransaction`.

    transaction: this DbTransaction
    The active database transaction to which the lock will be bound.
    resourceId: string
    The unique identifier of the resource to lock.
    logger: ILogger
    The logger used to record diagnostic and telemetry information.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a successful `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, an error result containing `DistributedLockErrors.LockAlreadyHeld`.

    Exceptions: ArgumentNullException: `transaction` or `logger` is `null`; ArgumentException: `resourceId` is empty or contains only white space; InvalidOperationException: The connection associated with `transaction` is `null`

  • methodTryAcquireInTransactionAsync
    public static async Task<Result<IDistributedLockHandle>> TryAcquireInTransactionAsync(this IDbTransaction transaction, string resourceId, ILogger logger, CancellationToken cancellationToken = default)

    Attempts to acquire an exclusive lock bound directly to an active `IDbTransaction`.

    transaction: this IDbTransaction
    The active database transaction to which the lock will be bound.
    resourceId: string
    The unique identifier of the resource to lock.
    logger: ILogger
    The logger used to record diagnostic and telemetry information.
    cancellationToken: CancellationToken
    A token that can be used to cancel the asynchronous operation.

    Retorna: A task representing the asynchronous operation. The task result contains a successful `Result<T>` with an `IDistributedLockHandle` if acquired; otherwise, an error result containing `DistributedLockErrors.LockAlreadyHeld`.

    Exceptions: ArgumentNullException: `transaction` or `logger` is `null`; ArgumentException: `resourceId` is empty or contains only white space; InvalidOperationException: The connection associated with `transaction` is `null`

Microsoft.Extensions.DependencyInjection#

7
class

MariaDbDistributedLockExtensions

Ensamblado: EricksonLopez.DistributedLock.MariaDb
public static class MariaDbDistributedLockExtensions

Provides extension methods for registering MariaDB distributed lock services in an `IServiceCollection`.

Miembros (2)

  • methodAddMariaDbDistributedLock
    public static IServiceCollection AddMariaDbDistributedLock(this IServiceCollection services, Func<DbConnection> connectionFactory, Action<MariaDbLockOptions>? configure = null)

    Registers the MariaDB distributed lock provider with a connection factory delegate.

    services: this IServiceCollection
    The service collection to configure.
    connectionFactory: Func<DbConnection>
    The delegate producing dedicated database connections.
    configure: Action<MariaDbLockOptions>?
    The optional configuration action for `MariaDbLockOptions`.

    Retorna: The configured service collection.

    Exceptions: ArgumentNullException: `services` or `connectionFactory` is `null`

  • methodAddMariaDbDistributedLock
    public static IServiceCollection AddMariaDbDistributedLock(this IServiceCollection services, string connectionString, Action<MariaDbLockOptions>? configure = null)

    Registers the MariaDB distributed lock provider using a connection string.

    services: this IServiceCollection
    The service collection to configure.
    connectionString: string
    The connection string used to connect to MariaDB.
    configure: Action<MariaDbLockOptions>?
    The optional configuration action for `MariaDbLockOptions`.

    Retorna: The configured service collection.

    Exceptions: ArgumentNullException: `services` is `null`; ArgumentException: `connectionString` is empty or contains only white space

class

MySqlDistributedLockExtensions

Ensamblado: EricksonLopez.DistributedLock.MySql
public static class MySqlDistributedLockExtensions

Provides extension methods for registering MySQL distributed lock services in an `IServiceCollection`.

Miembros (2)

  • methodAddMySqlDistributedLock
    public static IServiceCollection AddMySqlDistributedLock(this IServiceCollection services, Func<DbConnection> connectionFactory, Action<MySqlLockOptions>? configure = null)

    Registers the MySQL distributed lock provider with a connection factory delegate.

    services: this IServiceCollection
    The service collection to configure.
    connectionFactory: Func<DbConnection>
    The delegate producing dedicated database connections.
    configure: Action<MySqlLockOptions>?
    The optional configuration action for `MySqlLockOptions`.

    Retorna: The configured service collection.

    Exceptions: ArgumentNullException: `services` or `connectionFactory` is `null`

  • methodAddMySqlDistributedLock
    public static IServiceCollection AddMySqlDistributedLock(this IServiceCollection services, string connectionString, Action<MySqlLockOptions>? configure = null)

    Registers the MySQL distributed lock provider using a connection string.

    services: this IServiceCollection
    The service collection to configure.
    connectionString: string
    The connection string used to connect to MySQL.
    configure: Action<MySqlLockOptions>?
    The optional configuration action for `MySqlLockOptions`.

    Retorna: The configured service collection.

    Exceptions: ArgumentNullException: `services` is `null`; ArgumentException: `connectionString` is empty or contains only white space

class

OracleDistributedLockExtensions

Ensamblado: EricksonLopez.DistributedLock.Oracle
public static class OracleDistributedLockExtensions

Provides extension methods for registering Oracle distributed lock services in an `IServiceCollection`.

Miembros (2)

  • methodAddOracleDistributedLock
    public static IServiceCollection AddOracleDistributedLock(this IServiceCollection services, Func<DbConnection> connectionFactory, Action<OracleLockOptions>? configure = null)

    Registers the Oracle distributed lock provider with a connection factory delegate.

    services: this IServiceCollection
    The service collection to configure.
    connectionFactory: Func<DbConnection>
    The delegate producing dedicated database connections.
    configure: Action<OracleLockOptions>?
    The optional configuration action for `OracleLockOptions`.

    Retorna: The configured service collection.

    Exceptions: ArgumentNullException: `services` or `connectionFactory` is `null`

  • methodAddOracleDistributedLock
    public static IServiceCollection AddOracleDistributedLock(this IServiceCollection services, string connectionString, Action<OracleLockOptions>? configure = null)

    Registers the Oracle distributed lock provider using a connection string.

    services: this IServiceCollection
    The service collection to configure.
    connectionString: string
    The connection string used to connect to Oracle.
    configure: Action<OracleLockOptions>?
    The optional configuration action for `OracleLockOptions`.

    Retorna: The configured service collection.

    Exceptions: ArgumentNullException: `services` is `null`; ArgumentException: `connectionString` is empty or contains only white space

class

PostgresDistributedLockExtensions

Ensamblado: EricksonLopez.DistributedLock.PostgreSql
public static class PostgresDistributedLockExtensions

Provides extension methods for registering PostgreSQL distributed lock services in an `IServiceCollection`.

Miembros (2)

  • methodAddPostgresDistributedLock
    public static IServiceCollection AddPostgresDistributedLock(this IServiceCollection services, Func<IServiceProvider, DbConnection> connectionFactory, Action<PostgresLockOptions>? configure = null)

    Registers the PostgreSQL distributed lock provider with a `DbConnection` factory delegate.

    services: this IServiceCollection
    The service collection to configure.
    connectionFactory: Func<IServiceProvider, DbConnection>
    The factory delegate used to instantiate dedicated database connections.
    configure: Action<PostgresLockOptions>?
    The optional configuration action for `PostgresLockOptions`.

    Retorna: The configured service collection.

    Exceptions: ArgumentNullException: `services` or `connectionFactory` is `null`

  • methodAddPostgresDistributedLock
    public static IServiceCollection AddPostgresDistributedLock(this IServiceCollection services, Func<IServiceProvider, IDbConnection> connectionFactory, Action<PostgresLockOptions>? configure = null)

    Registers the PostgreSQL distributed lock provider with an `IDbConnection` factory delegate.

    services: this IServiceCollection
    The service collection to configure.
    connectionFactory: Func<IServiceProvider, IDbConnection>
    The factory delegate used to instantiate database connections.
    configure: Action<PostgresLockOptions>?
    The optional configuration action for `PostgresLockOptions`.

    Retorna: The configured service collection.

    Exceptions: ArgumentNullException: `services` or `connectionFactory` is `null`; InvalidOperationException: Thrown at runtime (during the first lock acquisition) when `connectionFactory` produces a connection that is not an instance of `DbConnection`. The PostgreSQL provider requires a concrete `DbConnection` subclass (e.g., `NpgsqlConnection`) for command execution

class

RedisDistributedLockExtensions

Ensamblado: EricksonLopez.DistributedLock.Redis
public static class RedisDistributedLockExtensions

Provides extension methods for registering Redis distributed lock services with an `IServiceCollection`.

Miembros (2)

  • methodAddRedisDistributedLock
    public static IServiceCollection AddRedisDistributedLock(this IServiceCollection services, Action<RedisLockOptions>? configure = null)

    Registers Redis distributed lock services resolving the required `IConnectionMultiplexer` from the service provider.

    services: this IServiceCollection
    The service collection to configure.
    configure: Action<RedisLockOptions>?
    An optional delegate to configure `RedisLockOptions`.

    Retorna: The same `IServiceCollection` instance so that multiple calls can be chained.

    Exceptions: ArgumentNullException: `services` is `null`

  • methodAddRedisDistributedLock
    public static IServiceCollection AddRedisDistributedLock(this IServiceCollection services, IConnectionMultiplexer multiplexer, Action<RedisLockOptions>? configure = null)

    Registers Redis distributed lock services using the specified connection multiplexer.

    services: this IServiceCollection
    The service collection to configure.
    multiplexer: IConnectionMultiplexer
    The connection multiplexer used to communicate with Redis.
    configure: Action<RedisLockOptions>?
    An optional delegate to configure `RedisLockOptions`.

    Retorna: The same `IServiceCollection` instance so that multiple calls can be chained.

    Exceptions: ArgumentNullException: `services` or `multiplexer` is `null`

class

SqlServerDistributedLockExtensions

Ensamblado: EricksonLopez.DistributedLock.SqlServer
public static class SqlServerDistributedLockExtensions

Provides extension methods for registering SQL Server distributed lock services with an `IServiceCollection`.

Miembros (2)

  • methodAddSqlServerDistributedLock
    public static IServiceCollection AddSqlServerDistributedLock(this IServiceCollection services, Func<DbConnection> connectionFactory, Action<SqlServerLockOptions>? configure = null)

    Registers SQL Server distributed lock services using the specified connection factory delegate.

    services: this IServiceCollection
    The service collection to configure.
    connectionFactory: Func<DbConnection>
    The factory delegate that creates new database connections.
    configure: Action<SqlServerLockOptions>?
    An optional delegate to configure `SqlServerLockOptions`.

    Retorna: The same `IServiceCollection` instance so that multiple calls can be chained.

    Exceptions: ArgumentNullException: `services` or `connectionFactory` is `null`

  • methodAddSqlServerDistributedLock
    public static IServiceCollection AddSqlServerDistributedLock(this IServiceCollection services, string connectionString, Action<SqlServerLockOptions>? configure = null)

    Registers SQL Server distributed lock services using the specified connection string.

    services: this IServiceCollection
    The service collection to configure.
    connectionString: string
    The connection string used to create SQL Server connections.
    configure: Action<SqlServerLockOptions>?
    An optional delegate to configure `SqlServerLockOptions`.

    Retorna: The same `IServiceCollection` instance so that multiple calls can be chained.

    Exceptions: ArgumentNullException: `services` is `null`; ArgumentException: `connectionString` is empty or contains only white space

class

SqliteDistributedLockExtensions

Ensamblado: EricksonLopez.DistributedLock.Sqlite
public static class SqliteDistributedLockExtensions

Provides extension methods for registering SQLite distributed lock services with an `IServiceCollection`.

Miembros (2)

  • methodAddSqliteDistributedLock
    public static IServiceCollection AddSqliteDistributedLock(this IServiceCollection services, Func<DbConnection> connectionFactory, Action<SqliteLockOptions>? configure = null)

    Registers SQLite distributed lock services using the specified connection factory delegate.

    services: this IServiceCollection
    The service collection to configure.
    connectionFactory: Func<DbConnection>
    The factory delegate that creates new database connections.
    configure: Action<SqliteLockOptions>?
    An optional delegate to configure `SqliteLockOptions`.

    Retorna: The same `IServiceCollection` instance so that multiple calls can be chained.

    Exceptions: ArgumentNullException: `services` or `connectionFactory` is `null`

  • methodAddSqliteDistributedLock
    public static IServiceCollection AddSqliteDistributedLock(this IServiceCollection services, string connectionString, Action<SqliteLockOptions>? configure = null)

    Registers SQLite distributed lock services using the specified connection string.

    services: this IServiceCollection
    The service collection to configure.
    connectionString: string
    The connection string used to create SQLite connections.
    configure: Action<SqliteLockOptions>?
    An optional delegate to configure `SqliteLockOptions`.

    Retorna: The same `IServiceCollection` instance so that multiple calls can be chained.

    Exceptions: ArgumentNullException: `services` is `null`; ArgumentException: `connectionString` is empty or contains only white space

Buscar en el Ecosistema EricksonLopez.*

Escribe el nombre de una librería, ID de paquete NuGet, tipo .NET o concepto arquitectónico para buscar en el portal.