Soenneker.Utils.AsyncSingleton
1.0.2
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Utils.AsyncSingleton --version 1.0.2
NuGet\Install-Package Soenneker.Utils.AsyncSingleton -Version 1.0.2
<PackageReference Include="Soenneker.Utils.AsyncSingleton" Version="1.0.2" />
<PackageVersion Include="Soenneker.Utils.AsyncSingleton" Version="1.0.2" />
<PackageReference Include="Soenneker.Utils.AsyncSingleton" />
paket add Soenneker.Utils.AsyncSingleton --version 1.0.2
#r "nuget: Soenneker.Utils.AsyncSingleton, 1.0.2"
#:package Soenneker.Utils.AsyncSingleton@1.0.2
#addin nuget:?package=Soenneker.Utils.AsyncSingleton&version=1.0.2
#tool nuget:?package=Soenneker.Utils.AsyncSingleton&version=1.0.2
Soenneker.Utils.AsyncSingleton
An externally initializing singleton that uses double-check asynchronous locking, with optional async and sync disposal
Installation
Install-Package Soenneker.Utils.AsyncSingleton
Example
The example below is a long-living HttpClient implementation using AsyncSingleton. It avoids the additional overhead of IHttpClientFactory, and doesn't rely on short-lived clients.
public class HttpRequester : IDisposable, IAsyncDisposable
{
private readonly AsyncSingleton<HttpClient> _client;
public HttpRequester()
{
// this func will lazily be called once it's retrieved the first time
_client = new AsyncSingleton<HttpClient>(() =>
{
var socketsHandler = new SocketsHttpHandler
{
PooledConnectionLifetime = TimeSpan.FromMinutes(10),
MaxConnectionsPerServer = 10
};
return new HttpClient(socketsHandler);
});
}
public async ValueTask Get()
{
// retrieve the singleton async, thus not blocking the calling thread
(await _client.Get()).GetAsync("https://google.com");
}
public ValueTask DisposeAsync()
{
GC.SuppressFinalize(false);
return _client.DisposeAsync();
}
public void Dispose()
{
GC.SuppressFinalize(false);
_client.Dispose();
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Nito.AsyncEx (>= 5.1.2)
NuGet packages (92)
Showing the top 5 NuGet packages that depend on Soenneker.Utils.AsyncSingleton:
| Package | Downloads |
|---|---|
|
Soenneker.Utils.MemoryStream
An easy modern MemoryStream utility |
|
|
Soenneker.Utils.Runtime
A collection of helpful runtime-based operations |
|
|
Soenneker.GitHub.Client
An async thread-safe singleton for Octokit's GitHubClient |
|
|
Soenneker.ServiceBus.Admin
A utility library for Azure Service Bus Administration client accessibility |
|
|
Soenneker.ServiceBus.Client
A utility library for Azure Service Bus client accessibility |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.804 | 39,474 | 6/19/2026 |
| 4.0.803 | 4,885 | 6/19/2026 |
| 4.0.802 | 2,908 | 6/19/2026 |
| 4.0.801 | 7,609 | 6/19/2026 |
| 4.0.800 | 8,575 | 6/18/2026 |
| 4.0.798 | 98 | 6/18/2026 |
| 4.0.797 | 77,591 | 6/16/2026 |
| 4.0.796 | 104,362 | 6/6/2026 |
| 4.0.795 | 16,373 | 6/6/2026 |
| 4.0.794 | 372 | 6/6/2026 |
| 4.0.792 | 7,048 | 6/5/2026 |
| 4.0.791 | 388 | 6/5/2026 |
| 4.0.789 | 6,387 | 6/5/2026 |
| 4.0.788 | 210,948 | 4/23/2026 |
| 4.0.787 | 3,790 | 4/23/2026 |
| 4.0.786 | 9,721 | 4/23/2026 |
| 4.0.785 | 18,608 | 4/22/2026 |
| 4.0.784 | 9,026 | 4/22/2026 |
| 4.0.783 | 177,297 | 3/13/2026 |
| 1.0.2 | 641 | 3/11/2023 |