WopiHost.MemoryLockProvider
9.3.0
dotnet add package WopiHost.MemoryLockProvider --version 9.3.0
NuGet\Install-Package WopiHost.MemoryLockProvider -Version 9.3.0
<PackageReference Include="WopiHost.MemoryLockProvider" Version="9.3.0" />
<PackageVersion Include="WopiHost.MemoryLockProvider" Version="9.3.0" />
<PackageReference Include="WopiHost.MemoryLockProvider" />
paket add WopiHost.MemoryLockProvider --version 9.3.0
#r "nuget: WopiHost.MemoryLockProvider, 9.3.0"
#:package WopiHost.MemoryLockProvider@9.3.0
#addin nuget:?package=WopiHost.MemoryLockProvider&version=9.3.0
#tool nuget:?package=WopiHost.MemoryLockProvider&version=9.3.0
WopiHost.MemoryLockProvider
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 | 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. |
-
net10.0
- Microsoft.AspNetCore.Authorization (>= 10.0.11)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.11)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.11)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.11)
- Microsoft.IdentityModel.Tokens (>= 8.22.0)
- WopiHost.Abstractions (>= 9.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.