Escapement.Azure.Functions.DistributedLock
0.1.15
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Escapement.Azure.Functions.DistributedLock --version 0.1.15
NuGet\Install-Package Escapement.Azure.Functions.DistributedLock -Version 0.1.15
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Escapement.Azure.Functions.DistributedLock" Version="0.1.15" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Escapement.Azure.Functions.DistributedLock" Version="0.1.15" />
<PackageReference Include="Escapement.Azure.Functions.DistributedLock" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Escapement.Azure.Functions.DistributedLock --version 0.1.15
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Escapement.Azure.Functions.DistributedLock, 0.1.15"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Escapement.Azure.Functions.DistributedLock@0.1.15
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Escapement.Azure.Functions.DistributedLock&version=0.1.15
#tool nuget:?package=Escapement.Azure.Functions.DistributedLock&version=0.1.15
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Escapement.Azure.Functions.DistributedLock
A small library to provide distributed locking for Azure Functions (Isolated Worker) using Azure Blob Storage leases. It is a lightweight replacement for [Microsoft.Azure.WebJobs.Singleton] that supports declarative attributes and programmatic lock acquisition.
Package: Escapement.Azure.Functions.DistributedLock
Summary
- Declarative locking via
[Singleton("key-{id}")]attribute for in-place migration from in-process to isolated Functions worker model. - Declarative locking via
[DistributedLock("key-{id}")]attribute. - Programmatic locking via
IDistributedLockHandlerFactoryandIDistributedLockHandler. - Uses Azure Blob leases with automatic background renewal and safe release.
- Testable design suitable for unit tests.
Install
dotnet add package Escapement.Azure.Functions.DistributedLock
Quick start
- Register services in
Program.cs:
services.AddSingleton(sp => new Azure.Storage.Blobs.BlobServiceClient(
Environment.GetEnvironmentVariable("AzureWebJobsStorage")
));
services.AddSingleton<IDistributedLockHandlerFactory, BlobLeaseHandlerFactory>();
// If using middleware: workerApplication.UseMiddleware<DistributedLockMiddleware>();
- Declarative usage (attribute on function):
[Singleton("ProcessOrder")]
[DistributedLock("order-lock-{orderId}")]
public async Task Run(string orderId, ILogger log)
{
// If this runs, the lock was acquired and is being renewed.
}
or
[Function("ProcessOrder")]
[DistributedLock("order-lock-{orderId}")]
public async Task Run(string orderId, ILogger log)
{
// If this runs, the lock was acquired and is being renewed.
}
- Programmatic usage (fine-grained control):
var handler = _lockHandlerFactory.CreateHandler();
await using var handle = await handler.TryAcquireLockAsync("my-key");
if (handle == null) { /* locked: skip or retry */ }
// critical section
Recommendations
- Use a consistent storage account and container name across hosts.
- Prefer
WaitForAcquireLockAsyncwith timeout for background jobs that must complete.
License and contribution See repository for full docs, tests, and contribution guidelines.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Azure.Storage.Blobs (>= 12.23.0)
- Microsoft.Azure.Functions.Worker.Core (>= 2.51.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.