Ir al contenido

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.

Primeros Pasos con EricksonLopez.DistributedLock

Instala EricksonLopez.DistributedLock.Abstractions (1.0.0 en NuGet) junto con el paquete de proveedor correspondiente (no existe un metapaquete raíz EricksonLopez.DistributedLock).

dotnet add package EricksonLopez.DistributedLock.Abstractions --version 1.0.0
Ventana de terminal
dotnet add package EricksonLopez.DistributedLock.Sqlite --version 1.0.0
# O elige .PostgreSql, .SqlServer, .MySql, .MariaDb, .Oracle, .Redis

Las extensiones DI (AddSqliteDistributedLock, AddPostgresDistributedLock, etc.) viven en 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);
}
}