Skip to content

Search EricksonLopez.* Ecosystem

Type a library name, NuGet package ID, .NET type, or architectural concept to search across the portal.

Getting Started with EricksonLopez.DistributedLock

Install EricksonLopez.DistributedLock.Abstractions (1.0.0 on NuGet) together with your chosen provider package (there is no root EricksonLopez.DistributedLock metapackage).

dotnet add package EricksonLopez.DistributedLock.Abstractions --version 1.0.0
Terminal window
dotnet add package EricksonLopez.DistributedLock.Sqlite --version 1.0.0
# Or choose .PostgreSql, .SqlServer, .MySql, .MariaDb, .Oracle, .Redis

Provider DI registration extensions (AddSqliteDistributedLock, AddPostgresDistributedLock, etc.) live in namespace Microsoft.Extensions.DependencyInjection;:

using System;
using System.Threading;
using System.Threading.Tasks;
using EricksonLopez.DistributedLock.Abstractions;
using EricksonLopez.Result;
using Microsoft.Extensions.DependencyInjection;
namespace Example.DistributedLockDocs;
public static class DistributedLockQuickStart
{
public static async Task<Result<string>> RunLockedWorkAsync(CancellationToken ct = default)
{
var services = new ServiceCollection();
services.AddLogging();
services.AddSqliteDistributedLock("Data Source=locks.db");
await using var sp = services.BuildServiceProvider();
var lockProvider = sp.GetRequiredService<IDistributedLockProvider>();
return await lockProvider.ExecuteWithLockAsync(
resourceId: "billing-run:2026-12",
timeout: TimeSpan.FromSeconds(5),
action: static async linkedCt =>
{
linkedCt.ThrowIfCancellationRequested();
await Task.CompletedTask;
return "Completed";
},
cancellationToken: ct);
}
}