MKS.KeyedLocking.Composite
1.0.0
dotnet add package MKS.KeyedLocking.Composite --version 1.0.0
NuGet\Install-Package MKS.KeyedLocking.Composite -Version 1.0.0
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="MKS.KeyedLocking.Composite" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MKS.KeyedLocking.Composite" Version="1.0.0" />
<PackageReference Include="MKS.KeyedLocking.Composite" />
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 MKS.KeyedLocking.Composite --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MKS.KeyedLocking.Composite, 1.0.0"
#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 MKS.KeyedLocking.Composite@1.0.0
#: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=MKS.KeyedLocking.Composite&version=1.0.0
#tool nuget:?package=MKS.KeyedLocking.Composite&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
MKS.KeyedLocking.Composite
Local in-memory barrier decorator over a distributed keyed lock backend.
Features
- Two-stage locking - In-memory semaphore first, then distributed lock
- Reduced network traffic - Only one thread per process hits Redis/Oracle at a time for the same key
- Always distributed - Remote lock is never skipped
- DI decorator -
AddCompositeKeyedLock()wraps the registered remote service
Installation
dotnet add package MKS.KeyedLocking.Composite
Dependency Injection
Register a distributed backend first, then add the composite decorator:
builder.Services.AddSingleton<IConnectionMultiplexer>(_ =>
ConnectionMultiplexer.Connect("localhost:6379"));
builder.Services.AddRedisKeyedLock()
.AddCompositeKeyedLock();
Or with Oracle:
builder.Services.AddOracleKeyedLock(connectionString)
.AddCompositeKeyedLock();
How It Works
When multiple threads in the same process request the same key:
- Threads wait on a cheap local
SemaphoreSlim(no network) - Only the local winner proceeds to acquire the Redis/Oracle lock
- On release, remote lock is released first, then local
This does not replace distributed locking. It only optimizes intra-process contention.
When to Use
- Multiple threads in one process frequently contend for the same keys
- You already use Redis or Oracle keyed locking
- You want to reduce polling/load on the distributed backend
When Not to Use
- Single-instance app with no distributed coordination needs - use
MKS.KeyedLocking.InMemoryalone
Requirements
- .NET 10.0
- MKS.KeyedLocking.Abstractions 1.0.0+
- MKS.KeyedLocking.InMemory 1.0.0+
- A registered remote backend (Redis or Oracle package)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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.
-
net10.0
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- MKS.KeyedLocking.Abstractions (>= 1.0.0)
- MKS.KeyedLocking.InMemory (>= 1.0.0)
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 |
|---|---|---|
| 1.0.0 | 136 | 7/6/2026 |
Version 1.0.0: Initial release.
CompositeKeyedLockService with AddCompositeKeyedLock DI extension.