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.
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.
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.
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.
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.
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.
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