WopiHost.MemoryLockProvider 9.3.0

dotnet add package WopiHost.MemoryLockProvider --version 9.3.0
                    
NuGet\Install-Package WopiHost.MemoryLockProvider -Version 9.3.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="WopiHost.MemoryLockProvider" Version="9.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WopiHost.MemoryLockProvider" Version="9.3.0" />
                    
Directory.Packages.props
<PackageReference Include="WopiHost.MemoryLockProvider" />
                    
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 WopiHost.MemoryLockProvider --version 9.3.0
                    
#r "nuget: WopiHost.MemoryLockProvider, 9.3.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 WopiHost.MemoryLockProvider@9.3.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=WopiHost.MemoryLockProvider&version=9.3.0
                    
Install as a Cake Addin
#tool nuget:?package=WopiHost.MemoryLockProvider&version=9.3.0
                    
Install as a Cake Tool

WopiHost.MemoryLockProvider

NuGet NuGet

Process-local in-memory implementation of IWopiLockProvider. Backed by a per-instance ConcurrentDictionary<string, WopiLockInfo> that AddMemoryLockProvider() registers as a singleton, so there's one shared store per process. Locks auto-expire after 30 minutes per the WOPI spec; expired entries are evicted lazily — on read, or when a new lock is added over an expired entry for the same file (a takeover, matching the Azure/Redis providers).

Use it for development, single-instance hosts, and tests. Don't use it for multi-instance deployments — locks are not shared across processes and are lost on restart.

IIS / app-pool recycling. "Single-instance" includes single-worker IIS sites only as long as the app pool stays warm. Recycles, idle shutdowns, and overlapped recycling all wipe the in-memory store, which surfaces as "Sorry, you cannot edit this document with others" on the next open of a previously-locked file (the WOPI client still holds the old lock id, the host no longer recognises it). For IIS — and any host with a non-trivial recycle policy — use a distributed provider such as WopiHost.AzureLockProvider.

Install

dotnet add package WopiHost.MemoryLockProvider

Register

services.AddMemoryLockProvider();

AddMemoryLockProvider registers MemoryLockProvider as the singleton IWopiLockProvider. Singleton lifetime ensures every request in the process shares the same in-memory lock dictionary — anything narrower would let concurrent requests see independent stores and silently break exclusion.

API

The interface is asynchronous so out-of-process implementations (Azure Blob, Redis, SQL) can plug in without sync-over-async. This in-memory provider just wraps its synchronous logic in Task.FromResult:

Task<WopiLockInfo?> GetLockAsync(string fileId, CancellationToken ct = default);
Task<WopiLockInfo?> AddLockAsync(string fileId, string lockId, CancellationToken ct = default);
Task<bool>          RefreshLockAsync(string fileId, string expectedExistingLockId, CancellationToken ct = default);
Task<bool>          RemoveLockAsync(string fileId, CancellationToken ct = default);
Task<bool>          TryUnlockAndRelockAsync(string fileId, string newLockId, string expectedExistingLockId, CancellationToken ct = default);

GetLockAsync returns null when the lock isn't present (or has expired and was evicted). WopiLockInfo carries LockId, FileId, DateCreated, and a computed IsExpiredAt(DateTimeOffset now) method.

TryUnlockAndRelockAsync is implemented with ConcurrentDictionary.TryUpdate against a snapshot — a true compare-and-swap, so a concurrent UnlockAndRelock from another caller correctly loses the race instead of silently overwriting.

See WopiHost.Abstractions for the full contract.

Lock-id comparison

The provider takes an optional IWopiLockComparer constructor parameter, defaulting to OrdinalWopiLockComparer.Instance (byte-exact). Plug in a custom comparer either via DI (services.Replace(ServiceDescriptor.Singleton<IWopiLockComparer, ...>())) or by passing it explicitly when constructing the provider. See the WopiHost.Abstractions README for the trade-offs (the bundled JsonShapedWopiLockComparer covers the OOS / M365-for-the-Web JSON-mutation quirk).

License

See the repo README.

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

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
9.3.0 1,709 9/4/2026
9.2.0 905 8/14/2026
9.1.0 1,232 7/3/2026
9.0.0 709 6/5/2026
8.0.0 394 5/14/2026
7.0.0 297 5/6/2026
6.0.0 184 5/3/2026
5.1.0 137 4/30/2026
5.0.5 156 3/1/2026
5.0.3 126 3/1/2026
5.0.2 191 3/1/2026