Escapement.Azure.Functions.DistributedLock 0.1.15

There is a newer version of this package available.
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" />
                    
Directory.Packages.props
<PackageReference Include="Escapement.Azure.Functions.DistributedLock" />
                    
Project file
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
                    
#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
                    
Install as a Cake Addin
#tool nuget:?package=Escapement.Azure.Functions.DistributedLock&version=0.1.15
                    
Install as a Cake Tool

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 IDistributedLockHandlerFactory and IDistributedLockHandler.
  • 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

  1. 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>();
  1. 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.
}
  1. 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 WaitForAcquireLockAsync with timeout for background jobs that must complete.

License and contribution See repository for full docs, tests, and contribution guidelines.

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

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.17 161 1/3/2026
0.1.16 133 1/3/2026
0.1.15 274 12/15/2025
0.1.13 237 12/14/2025
0.1.12 246 12/14/2025