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

Install EricksonLopez.Concurrency (2.0.0 on NuGet) together with EricksonLopez.Concurrency.Result for functional conflict handling.

dotnet add package EricksonLopez.Concurrency --version 2.0.0
Terminal window
dotnet add package EricksonLopez.Concurrency.Result --version 2.0.0
dotnet add package EricksonLopez.Concurrency.Dapper --version 2.0.0
using System.Threading;
using System.Threading.Tasks;
using EricksonLopez.Concurrency.Abstractions;
using EricksonLopez.Concurrency.DependencyInjection;
using EricksonLopez.Concurrency.Result;
using EricksonLopez.Result;
using Microsoft.Extensions.DependencyInjection;
namespace Example.ConcurrencyDocs;
public sealed record OrderState(string Id, string Status, long Version) : IVersionedEntity;
public static class ConcurrencyQuickStart
{
public static async Task<Result<OrderState>> ApproveOrderAsync(CancellationToken ct = default)
{
var services = new ServiceCollection();
services.AddEricksonLopezConcurrency();
using var sp = services.BuildServiceProvider();
var controller = sp.GetRequiredService<IConcurrencyController>();
var current = new OrderState("ord-1", "Pending", 1);
CasResult<OrderState> cas = await controller.ExecuteCasAsync(
entity: current,
expected: ExpectedVersion.Specific(1),
entityId: current.Id,
mutate: static (state, _) => state with { Status = "Approved", Version = state.Version + 1 },
cancellationToken: ct);
return cas.ToResult();
}
}