NCode.Disposables
6.0.0
Prefix Reserved
See the version list below for details.
dotnet add package NCode.Disposables --version 6.0.0
NuGet\Install-Package NCode.Disposables -Version 6.0.0
<PackageReference Include="NCode.Disposables" Version="6.0.0" />
<PackageVersion Include="NCode.Disposables" Version="6.0.0" />
<PackageReference Include="NCode.Disposables" />
paket add NCode.Disposables --version 6.0.0
#r "nuget: NCode.Disposables, 6.0.0"
#:package NCode.Disposables@6.0.0
#addin nuget:?package=NCode.Disposables&version=6.0.0
#tool nuget:?package=NCode.Disposables&version=6.0.0
NCode.Disposables
Building blocks for IDisposable and IAsyncDisposable in .NET: run an action on dispose, dispose many resources in reverse order, swap the resource an aggregate holds, share a resource through reference-counted leases, and dispose on a synchronization context.
Installation
dotnet add package NCode.Disposables
The package depends on no other package. Its target frameworks are the ones its .csproj declares; they are listed on nuget.org's Frameworks tab and shown by the badge above. CHANGELOG.md records when a framework is added or dropped.
Example
Every type is in the NCode.Disposables namespace. Disposable.Create turns a delegate into an IDisposable, and Disposable.Collection disposes many of them together, the last one added first:
var log = new List<string>();
var connection = Disposable.Create(() => log.Add("connection closed"));
var fileLock = Disposable.Create(() => log.Add("lock released"));
using (var resources = Disposable.Collection())
{
resources.Add(connection);
resources.Add(fileLock);
}
// log: "lock released", "connection closed": the last resource added is disposed first
By default the action runs on the first Dispose only; pass idempotent: false to run it on every call:
var count = 0;
var once = Disposable.Create(() => count++);
once.Dispose();
once.Dispose(); // count == 1: the action runs on the first call only
var everyTime = Disposable.Create(() => count++, idempotent: false);
everyTime.Dispose();
everyTime.Dispose(); // count == 3: the action runs on every call
SharedReference.Create puts a resource behind a reference count, and the resource is disposed when the last lease is disposed:
var log = new List<string>();
var connection = Disposable.Create(() => log.Add("connection closed"));
var first = SharedReference.Create(connection);
var second = first.AddReference();
first.Dispose(); // log is empty: second still holds a reference
second.Dispose(); // log: "connection closed"
Learn more
- README and samples: every type, with a tested sample for each
- API overview
- Thread safety
- Changelog
- Report a vulnerability or verify a 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. |
-
net10.0
- No dependencies.
NuGet packages (25)
Showing the top 5 NuGet packages that depend on NCode.Disposables:
| Package | Downloads |
|---|---|
|
NCode.Collections.Providers
Default implementations for dynamic, change-aware collection providers. Includes static, observable, composite, and periodic polling data sources with automatic change notifications via IChangeToken. Provides dependency injection integration with Microsoft.Extensions.DependencyInjection. |
|
|
NCode.Identity.OpenId.Abstractions
Package Description |
|
|
NCode.Identity.OpenId.Accounts.Abstractions
Package Description |
|
|
NCode.Identity.OpenId.Authentication.Abstractions
Package Description |
|
|
NCode.Identity.Secrets
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 7.1.0 | 0 | 11/25/2026 |
| 7.0.0 | 0 | 11/25/2026 |
| 6.0.0 | 0 | 11/24/2026 |
| 5.3.0 | 4,085 | 1/17/2026 |
| 5.2.1 | 255 | 11/29/2024 |
| 5.1.1 | 234 | 11/27/2024 |
| 5.1.0 | 250 | 5/16/2024 |
| 5.0.2 | 261 | 5/16/2024 |
| 5.0.1 | 262 | 5/16/2024 |
| 5.0.0 | 239 | 5/16/2024 |
| 4.4.0 | 260 | 5/15/2024 |
| 4.3.0 | 248 | 5/15/2024 |
| 4.2.0 | 240 | 4/29/2024 |
| 4.1.0 | 244 | 4/28/2024 |
| 4.0.0 | 240 | 4/21/2024 |
| 3.1.0 | 234 | 4/21/2024 |
| 3.0.1 | 244 | 4/21/2024 |
| 3.0.0 | 252 | 4/21/2024 |
| 2.0.2 | 1,935 | 1/22/2017 |
| 2.0.1 | 1,364 | 1/22/2017 |
See the changelog: https://github.com/NCodeGroup/NCode.Disposables/blob/HEAD/CHANGELOG.md