Soenneker.Utils.AsyncSingleton
1.0.22
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Utils.AsyncSingleton --version 1.0.22
NuGet\Install-Package Soenneker.Utils.AsyncSingleton -Version 1.0.22
<PackageReference Include="Soenneker.Utils.AsyncSingleton" Version="1.0.22" />
<PackageVersion Include="Soenneker.Utils.AsyncSingleton" Version="1.0.22" />
<PackageReference Include="Soenneker.Utils.AsyncSingleton" />
paket add Soenneker.Utils.AsyncSingleton --version 1.0.22
#r "nuget: Soenneker.Utils.AsyncSingleton, 1.0.22"
#:package Soenneker.Utils.AsyncSingleton@1.0.22
#addin nuget:?package=Soenneker.Utils.AsyncSingleton&version=1.0.22
#tool nuget:?package=Soenneker.Utils.AsyncSingleton&version=1.0.22
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 execute once it's retrieved the first time.
// Other threads calling this at the same moment will asynchronously wait,
// and then utilize the HttpClient that was created from the first caller.
_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 (await _client.Get()).GetAsync("https://google.com");
}
// Disposal is not necessary for AsyncSingleton unless the type used is IDisposable/IAsyncDisposable
public ValueTask DisposeAsync()
{
GC.SuppressFinalize(this);
return _client.DisposeAsync();
}
public void Dispose()
{
GC.SuppressFinalize(this);
_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 (19)
Showing the top 5 NuGet packages that depend on Soenneker.Utils.AsyncSingleton:
| Package | Downloads |
|---|---|
|
Soenneker.Utils.Runtime
Detects the current operating system, common hosting environments, and container execution. |
|
|
Soenneker.Utils.MemoryStream
An easy modern MemoryStream utility |
|
|
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 |
|
|
Soenneker.Azure.OpenAI.Client
An async thread-safe singleton for the Azure OpenAI client |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 11.0.893 | 10,971 | 11/11/2026 |
| 11.0.891 | 14,096 | 11/11/2026 |
| 11.0.890 | 4,236 | 11/11/2026 |
| 11.0.889 | 12,511 | 11/10/2026 |
| 11.0.888 | 667 | 11/10/2026 |
| 11.0.887 | 71,072 | 11/3/2026 |
| 11.0.886 | 84,200 | 10/26/2026 |
| 11.0.885 | 3,553 | 10/26/2026 |
| 11.0.884 | 3,660 | 10/26/2026 |
| 11.0.883 | 4,495 | 10/26/2026 |
| 11.0.882 | 193 | 10/26/2026 |
| 4.0.881 | 80,835 | 10/15/2026 |
| 4.0.880 | 533 | 10/15/2026 |
| 4.0.879 | 614 | 10/14/2026 |
| 4.0.875 | 11,178 | 10/14/2026 |
| 4.0.874 | 242 | 10/14/2026 |
| 4.0.866 | 17,479 | 10/13/2026 |
| 4.0.865 | 10,029 | 10/13/2026 |
| 4.0.862 | 36,456 | 10/12/2026 |
| 1.0.22 | 22,100 | 5/30/2023 |