Soenneker.Utils.AsyncSingleton 2.1.184

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package Soenneker.Utils.AsyncSingleton --version 2.1.184
NuGet\Install-Package Soenneker.Utils.AsyncSingleton -Version 2.1.184
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="Soenneker.Utils.AsyncSingleton" Version="2.1.184" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Soenneker.Utils.AsyncSingleton --version 2.1.184
#r "nuget: Soenneker.Utils.AsyncSingleton, 2.1.184"
#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.
// Install Soenneker.Utils.AsyncSingleton as a Cake Addin
#addin nuget:?package=Soenneker.Utils.AsyncSingleton&version=2.1.184

// Install Soenneker.Utils.AsyncSingleton as a Cake Tool
#tool nuget:?package=Soenneker.Utils.AsyncSingleton&version=2.1.184

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

alternate text is missing from this package README image Soenneker.Utils.AsyncSingleton

An externally initializing singleton that uses double-check asynchronous locking, with optional async and sync disposal

Installation

dotnet add 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 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. 
.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. 
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (18)

Showing the top 5 NuGet packages that depend on Soenneker.Utils.AsyncSingleton:

Package Downloads
Soenneker.Utils.MemoryStream The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

An easy modern MemoryStream utility

Soenneker.Redis.Client The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

A utility library for Redis client accessibility

Soenneker.Cosmos.Client The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

A utility library for Azure Cosmos client accessibility

Soenneker.Blob.Container The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

A utility library for Azure Blob storage container operations

Soenneker.ServiceBus.Admin The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

A utility library for Azure Service Bus Administration client accessibility

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.184 0 2/29/2024
2.1.183 16 2/29/2024
2.1.182 256 2/29/2024
2.1.181 1,371 2/26/2024
2.1.180 3,037 2/25/2024
2.1.179 908 2/25/2024
2.1.178 3,143 2/23/2024
2.1.177 3,283 2/22/2024
2.1.176 877 2/22/2024
2.1.175 1,001 2/21/2024
2.1.174 1,850 2/21/2024
2.1.173 1,741 2/21/2024
2.1.172 2,108 2/21/2024
2.1.171 921 2/21/2024
2.1.170 116 2/21/2024
2.1.169 1,758 2/21/2024
2.1.168 604 2/20/2024
2.1.167 83 2/20/2024
2.1.166 74 2/20/2024
2.1.165 2,586 2/20/2024
2.1.164 1,976 2/20/2024
2.1.163 1,760 2/20/2024
2.1.162 4,062 2/19/2024
2.1.161 3,154 2/17/2024
2.1.160 1,248 2/17/2024
2.1.159 941 2/16/2024
2.1.158 713 2/16/2024
2.1.157 1,183 2/16/2024
2.1.156 1,665 2/16/2024
2.1.155 2,142 2/16/2024
2.1.154 97 2/16/2024
2.1.153 1,028 2/16/2024
2.1.152 100 2/16/2024
2.1.151 88 2/16/2024
2.1.150 3,600 2/14/2024
2.1.149 1,429 2/13/2024
2.1.148 1,768 2/13/2024
2.1.147 2,179 2/13/2024
2.1.146 2,012 2/13/2024
2.1.145 2,977 2/12/2024
2.1.144 412 2/11/2024
2.1.143 3,171 2/11/2024
2.1.142 1,768 2/11/2024
2.1.141 3,656 2/10/2024
2.1.140 454 2/9/2024
2.1.139 3,272 2/9/2024
2.1.138 2,130 2/9/2024
2.1.137 591 2/8/2024
2.1.136 2,625 2/8/2024
2.1.135 1,059 2/8/2024
2.1.134 5,819 2/8/2024
2.1.133 146 2/8/2024
2.1.132 108 2/8/2024
2.1.131 3,087 2/7/2024
2.1.130 1,266 2/7/2024
2.1.129 2,076 2/7/2024
2.1.128 676 2/7/2024
2.1.127 525 2/6/2024
2.1.126 1,700 2/6/2024
2.1.125 123 2/6/2024
2.1.124 4,582 2/5/2024
2.1.123 2,983 2/4/2024
2.1.122 3,170 2/2/2024
2.1.121 3,888 1/31/2024
2.1.120 3,800 1/29/2024
2.1.119 2,325 1/29/2024
2.1.118 1,567 1/29/2024
2.1.117 2,447 1/28/2024
2.1.116 3,321 1/28/2024
2.1.115 1,839 1/28/2024
2.1.114 1,133 1/28/2024
2.1.113 1,421 1/27/2024
2.1.112 1,285 1/27/2024
2.1.111 3,445 1/27/2024
2.1.110 1,744 1/27/2024
2.1.109 4,062 1/27/2024
2.1.108 1,072 1/26/2024
2.1.107 1,274 1/26/2024
2.1.106 1,674 1/26/2024
2.1.105 3,187 1/26/2024
2.1.104 1,467 1/26/2024
2.1.103 834 1/26/2024
2.1.102 2,936 1/25/2024
2.1.101 2,236 1/25/2024
2.1.100 1,092 1/25/2024
2.1.99 3,616 1/25/2024
2.1.98 3,675 1/19/2024
2.1.97 3,710 1/15/2024
2.1.96 1,666 1/15/2024
2.1.95 1,310 1/15/2024
2.1.94 3,407 1/15/2024
2.1.93 3,511 1/15/2024
2.1.92 3,447 1/14/2024
2.1.91 4,167 1/13/2024
2.1.90 3,481 1/12/2024
2.1.89 3,526 1/11/2024
2.1.88 4,834 1/7/2024
2.1.87 3,843 1/5/2024
2.1.86 1,661 1/5/2024
2.1.85 2,178 1/5/2024
2.1.84 4,149 1/3/2024
2.1.83 2,454 1/1/2024
2.1.82 3,451 12/28/2023
2.1.81 1,331 12/28/2023
2.1.80 1,368 12/28/2023
2.1.79 3,053 12/27/2023
2.1.78 1,419 12/27/2023
2.1.77 153 12/27/2023
2.1.76 5,895 12/25/2023
2.1.75 3,146 12/25/2023
2.1.74 1,634 12/25/2023
2.1.73 449 12/25/2023
2.1.72 180 12/25/2023
2.1.71 4,516 12/24/2023
2.1.70 3,643 12/23/2023
2.1.69 1,909 12/23/2023
2.1.68 1,130 12/23/2023
2.1.67 2,579 12/23/2023
2.1.66 163 12/23/2023
2.1.65 5,494 12/19/2023
2.1.64 1,493 12/19/2023
2.1.63 3,764 12/12/2023
2.1.62 296 12/12/2023
2.1.61 1,858 12/11/2023
2.1.60 1,484 12/11/2023
2.1.59 802 12/11/2023
2.1.58 1,103 12/11/2023
2.1.57 559 12/10/2023
2.1.56 556 12/10/2023
2.1.55 1,234 12/10/2023
2.1.54 736 12/10/2023
2.1.53 5,697 12/10/2023
2.1.52 1,276 12/9/2023
2.1.51 717 12/9/2023
2.1.50 1,084 12/9/2023
2.1.49 1,710 12/9/2023
2.1.48 148 12/9/2023
2.1.47 845 12/9/2023
2.1.46 202 12/9/2023
2.1.45 1,892 12/9/2023
2.1.44 173 12/9/2023
2.1.43 3,131 12/9/2023
2.1.42 4,911 12/6/2023
2.1.41 820 12/6/2023
2.1.40 1,114 12/6/2023
2.1.39 2,663 12/5/2023
2.1.38 1,364 12/5/2023
2.1.37 740 12/5/2023
2.1.36 1,922 12/5/2023
2.1.35 165 12/5/2023
2.1.34 1,625 12/5/2023
2.1.33 178 12/5/2023
2.1.32 1,058 12/4/2023
2.1.31 1,044 12/4/2023
2.1.30 179 12/4/2023
2.1.29 5,924 12/4/2023
2.1.28 1,947 11/27/2023
2.1.27 865 11/26/2023
2.1.26 2,219 11/23/2023
2.1.25 1,909 11/23/2023
2.1.24 2,347 11/23/2023
2.1.23 183 11/23/2023
2.1.22 4,614 11/20/2023
2.1.21 2,197 11/20/2023
2.1.20 3,530 11/19/2023
2.1.19 1,974 11/19/2023
2.1.18 2,701 11/19/2023
2.1.17 715 11/18/2023
2.1.16 3,518 11/18/2023
2.1.15 822 11/18/2023
2.1.14 2,261 11/18/2023
2.1.13 465 11/18/2023
2.1.12 2,351 11/17/2023
2.1.11 1,940 11/17/2023
2.1.10 1,375 11/17/2023
2.1.9 236 11/17/2023
2.1.8 2,268 11/17/2023
2.1.7 1,305 11/17/2023
2.1.6 1,644 11/17/2023
2.1.5 1,090 11/17/2023
2.1.4 367 11/17/2023
2.1.3 2,076 11/16/2023
2.0.78 693 11/15/2023
2.0.77 183 11/15/2023
2.0.76 1,926 11/15/2023
2.0.2 192 11/16/2023
2.0.1 156 11/16/2023
1.0.75 2,845 11/13/2023
1.0.74 4,247 11/10/2023
1.0.73 3,319 11/9/2023
1.0.72 2,243 11/8/2023
1.0.71 3,439 11/7/2023
1.0.70 1,737 11/6/2023
1.0.69 2,174 11/3/2023
1.0.68 3,901 11/2/2023
1.0.67 2,471 11/1/2023
1.0.66 7,450 10/26/2023
1.0.65 4,643 10/19/2023
1.0.64 2,020 10/18/2023
1.0.63 1,973 10/17/2023
1.0.62 2,402 10/16/2023
1.0.61 4,345 10/13/2023
1.0.60 2,602 10/12/2023
1.0.59 8,071 9/18/2023
1.0.58 171 9/18/2023
1.0.57 5,444 9/14/2023
1.0.56 5,154 8/31/2023
1.0.55 2,650 8/30/2023
1.0.54 2,265 8/29/2023
1.0.53 2,227 8/28/2023
1.0.52 4,174 8/25/2023
1.0.51 2,295 8/24/2023
1.0.50 5,766 8/21/2023
1.0.49 2,256 8/18/2023
1.0.48 2,152 8/17/2023
1.0.47 4,071 8/16/2023
1.0.46 6,701 8/10/2023
1.0.45 2,353 8/9/2023
1.0.44 3,903 8/8/2023
1.0.43 3,319 8/7/2023
1.0.42 3,513 8/4/2023
1.0.41 6,382 7/13/2023
1.0.40 4,303 7/11/2023
1.0.39 2,626 7/10/2023
1.0.38 3,293 7/7/2023
1.0.37 244 7/7/2023
1.0.36 9,137 6/30/2023
1.0.35 4,761 6/28/2023
1.0.34 4,929 6/27/2023
1.0.33 5,598 6/26/2023
1.0.32 3,416 6/23/2023
1.0.31 6,843 6/21/2023
1.0.30 7,134 6/15/2023
1.0.29 2,759 6/14/2023
1.0.28 7,627 6/9/2023
1.0.27 3,340 6/8/2023
1.0.26 4,108 6/7/2023
1.0.25 4,808 6/6/2023
1.0.24 251 6/6/2023
1.0.23 3,917 6/5/2023
1.0.22 14,199 5/30/2023
1.0.21 16,510 5/29/2023
1.0.20 5,851 5/26/2023
1.0.19 6,769 5/25/2023
1.0.18 7,013 5/24/2023
1.0.17 4,677 5/24/2023
1.0.16 1,345 5/23/2023
1.0.15 1,253 5/23/2023
1.0.12 2,586 5/22/2023
1.0.11 15,674 5/16/2023
1.0.10 13,151 4/20/2023
1.0.9 12,747 4/3/2023
1.0.8 953 4/3/2023
1.0.7 2,003 3/23/2023
1.0.5 622 3/13/2023
1.0.4 389 3/11/2023
1.0.3 308 3/11/2023
1.0.2 309 3/11/2023
1.0.1 364 3/11/2023