Soenneker.Utils.AsyncSingleton 2.1.230

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.230
NuGet\Install-Package Soenneker.Utils.AsyncSingleton -Version 2.1.230
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.230" />
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.230
#r "nuget: Soenneker.Utils.AsyncSingleton, 2.1.230"
#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.230

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

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)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (20)

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.230 3,114 4/19/2024
2.1.229 4,381 4/18/2024
2.1.228 4,596 4/12/2024
2.1.227 718 4/12/2024
2.1.226 1,148 4/12/2024
2.1.225 961 4/12/2024
2.1.224 662 4/12/2024
2.1.223 964 4/12/2024
2.1.222 366 4/12/2024
2.1.221 73 4/12/2024
2.1.220 2,555 4/10/2024
2.1.219 9,825 4/10/2024
2.1.218 467 4/10/2024
2.1.217 5,429 4/2/2024
2.1.216 881 4/1/2024
2.1.215 5,179 3/29/2024
2.1.214 3,734 3/25/2024
2.1.213 428 3/25/2024
2.1.212 5,289 3/20/2024
2.1.211 3,629 3/19/2024
2.1.210 2,187 3/19/2024
2.1.209 2,376 3/18/2024
2.1.208 5,367 3/15/2024
2.1.207 3,665 3/13/2024
2.1.206 1,385 3/13/2024
2.1.205 1,818 3/13/2024
2.1.204 122 3/13/2024
2.1.203 104 3/13/2024
2.1.202 1,167 3/13/2024
2.1.201 111 3/13/2024
2.1.200 2,671 3/12/2024
2.1.199 3,381 3/12/2024
2.1.198 4,338 3/11/2024
2.1.197 3,020 3/11/2024
2.1.196 3,241 3/10/2024
2.1.195 4,284 3/8/2024
2.1.194 391 3/8/2024
2.1.193 3,068 3/8/2024
2.1.192 3,917 3/6/2024
2.1.191 3,964 3/4/2024
2.1.190 2,161 3/4/2024
2.1.189 4,578 3/2/2024
2.1.188 1,127 3/2/2024
2.1.187 1,394 3/2/2024
2.1.186 827 3/2/2024
2.1.185 541 3/2/2024
2.1.184 2,892 2/29/2024
2.1.183 977 2/29/2024
2.1.182 1,494 2/29/2024
2.1.181 2,895 2/26/2024
2.1.180 11,705 2/25/2024
2.1.179 1,383 2/25/2024
2.1.178 4,630 2/23/2024
2.1.177 4,451 2/22/2024
2.1.176 1,206 2/22/2024
2.1.175 1,415 2/21/2024
2.1.174 2,406 2/21/2024
2.1.173 2,155 2/21/2024
2.1.172 2,727 2/21/2024
2.1.171 1,138 2/21/2024
2.1.170 290 2/21/2024
2.1.169 2,594 2/21/2024
2.1.168 729 2/20/2024
2.1.167 161 2/20/2024
2.1.166 166 2/20/2024
2.1.165 3,325 2/20/2024
2.1.164 2,457 2/20/2024
2.1.163 2,400 2/20/2024
2.1.162 5,091 2/19/2024
2.1.161 4,066 2/17/2024
2.1.160 1,688 2/17/2024
2.1.159 1,145 2/16/2024
2.1.158 872 2/16/2024
2.1.157 1,460 2/16/2024
2.1.156 2,333 2/16/2024
2.1.155 2,614 2/16/2024
2.1.154 197 2/16/2024
2.1.153 1,286 2/16/2024
2.1.152 201 2/16/2024
2.1.151 189 2/16/2024
2.1.150 4,624 2/14/2024
2.1.149 1,958 2/13/2024
2.1.148 2,334 2/13/2024
2.1.147 2,797 2/13/2024
2.1.146 2,691 2/13/2024
2.1.145 3,725 2/12/2024
2.1.144 591 2/11/2024
2.1.143 4,088 2/11/2024
2.1.142 2,318 2/11/2024
2.1.141 4,778 2/10/2024
2.1.140 544 2/9/2024
2.1.139 4,428 2/9/2024
2.1.138 2,743 2/9/2024
2.1.137 730 2/8/2024
2.1.136 3,522 2/8/2024
2.1.135 1,417 2/8/2024
2.1.134 7,671 2/8/2024
2.1.133 259 2/8/2024
2.1.132 195 2/8/2024
2.1.131 4,027 2/7/2024
2.1.130 1,547 2/7/2024
2.1.129 2,700 2/7/2024
2.1.128 883 2/7/2024
2.1.127 803 2/6/2024
2.1.126 2,129 2/6/2024
2.1.125 233 2/6/2024
2.1.124 5,735 2/5/2024
2.1.123 3,771 2/4/2024
2.1.122 4,039 2/2/2024
2.1.121 4,881 1/31/2024
2.1.120 4,765 1/29/2024
2.1.119 2,784 1/29/2024
2.1.118 1,910 1/29/2024
2.1.117 3,147 1/28/2024
2.1.116 4,048 1/28/2024
2.1.115 2,351 1/28/2024
2.1.114 1,305 1/28/2024
2.1.113 1,938 1/27/2024
2.1.112 1,617 1/27/2024
2.1.111 4,292 1/27/2024
2.1.110 1,973 1/27/2024
2.1.109 5,212 1/27/2024
2.1.108 1,277 1/26/2024
2.1.107 1,667 1/26/2024
2.1.106 2,220 1/26/2024
2.1.105 3,962 1/26/2024
2.1.104 1,895 1/26/2024
2.1.103 990 1/26/2024
2.1.102 3,518 1/25/2024
2.1.101 2,730 1/25/2024
2.1.100 1,340 1/25/2024
2.1.99 4,697 1/25/2024
2.1.98 4,205 1/19/2024
2.1.97 4,559 1/15/2024
2.1.96 2,133 1/15/2024
2.1.95 1,593 1/15/2024
2.1.94 4,218 1/15/2024
2.1.93 4,310 1/15/2024
2.1.92 4,187 1/14/2024
2.1.91 5,150 1/13/2024
2.1.90 4,348 1/12/2024
2.1.89 4,208 1/11/2024
2.1.88 5,879 1/7/2024
2.1.87 4,621 1/5/2024
2.1.86 2,100 1/5/2024
2.1.85 2,574 1/5/2024
2.1.84 4,978 1/3/2024
2.1.83 3,034 1/1/2024
2.1.82 4,149 12/28/2023
2.1.81 1,681 12/28/2023
2.1.80 1,628 12/28/2023
2.1.79 3,743 12/27/2023
2.1.78 1,694 12/27/2023
2.1.77 255 12/27/2023
2.1.76 7,104 12/25/2023
2.1.75 3,910 12/25/2023
2.1.74 1,947 12/25/2023
2.1.73 532 12/25/2023
2.1.72 283 12/25/2023
2.1.71 5,455 12/24/2023
2.1.70 4,402 12/23/2023
2.1.69 2,282 12/23/2023
2.1.68 1,343 12/23/2023
2.1.67 3,250 12/23/2023
2.1.66 259 12/23/2023
2.1.65 6,406 12/19/2023
2.1.64 1,866 12/19/2023
2.1.63 4,436 12/12/2023
2.1.62 388 12/12/2023
2.1.61 2,233 12/11/2023
2.1.60 1,795 12/11/2023
2.1.59 1,074 12/11/2023
2.1.58 1,345 12/11/2023
2.1.57 659 12/10/2023
2.1.56 655 12/10/2023
2.1.55 1,554 12/10/2023
2.1.54 957 12/10/2023
2.1.53 6,832 12/10/2023
2.1.52 1,548 12/9/2023
2.1.51 881 12/9/2023
2.1.50 1,320 12/9/2023
2.1.49 2,091 12/9/2023
2.1.48 234 12/9/2023
2.1.47 964 12/9/2023
2.1.46 307 12/9/2023
2.1.45 2,456 12/9/2023
2.1.44 267 12/9/2023
2.1.43 3,692 12/9/2023
2.1.42 5,641 12/6/2023
2.1.41 1,039 12/6/2023
2.1.40 1,415 12/6/2023
2.1.39 3,259 12/5/2023
2.1.38 1,646 12/5/2023
2.1.37 951 12/5/2023
2.1.36 2,376 12/5/2023
2.1.35 255 12/5/2023
2.1.34 2,038 12/5/2023
2.1.33 266 12/5/2023
2.1.32 1,218 12/4/2023
2.1.31 1,345 12/4/2023
2.1.30 283 12/4/2023
2.1.29 7,245 12/4/2023
2.1.28 2,235 11/27/2023
2.1.27 1,085 11/26/2023
2.1.26 2,751 11/23/2023
2.1.25 2,345 11/23/2023
2.1.24 2,858 11/23/2023
2.1.23 268 11/23/2023
2.1.22 5,647 11/20/2023
2.1.21 2,748 11/20/2023
2.1.20 4,234 11/19/2023
2.1.19 2,443 11/19/2023
2.1.18 3,363 11/19/2023
2.1.17 907 11/18/2023
2.1.16 4,227 11/18/2023
2.1.15 1,122 11/18/2023
2.1.14 2,790 11/18/2023
2.1.13 690 11/18/2023
2.1.12 2,849 11/17/2023
2.1.11 2,382 11/17/2023
2.1.10 1,638 11/17/2023
2.1.9 319 11/17/2023
2.1.8 2,923 11/17/2023
2.1.7 1,572 11/17/2023
2.1.6 1,970 11/17/2023
2.1.5 1,176 11/17/2023
2.1.4 458 11/17/2023
2.1.3 2,563 11/16/2023
2.0.78 910 11/15/2023
2.0.77 282 11/15/2023
2.0.76 2,292 11/15/2023
2.0.2 288 11/16/2023
2.0.1 254 11/16/2023
1.0.75 3,347 11/13/2023
1.0.74 4,972 11/10/2023
1.0.73 4,020 11/9/2023
1.0.72 2,687 11/8/2023
1.0.71 4,198 11/7/2023
1.0.70 2,022 11/6/2023
1.0.69 2,568 11/3/2023
1.0.68 4,846 11/2/2023
1.0.67 2,696 11/1/2023
1.0.66 8,626 10/26/2023
1.0.65 5,485 10/19/2023
1.0.64 2,498 10/18/2023
1.0.63 2,296 10/17/2023
1.0.62 2,784 10/16/2023
1.0.61 5,419 10/13/2023
1.0.60 3,134 10/12/2023
1.0.59 9,294 9/18/2023
1.0.58 277 9/18/2023
1.0.57 6,514 9/14/2023
1.0.56 5,919 8/31/2023
1.0.55 3,176 8/30/2023
1.0.54 2,556 8/29/2023
1.0.53 2,516 8/28/2023
1.0.52 4,991 8/25/2023
1.0.51 2,694 8/24/2023
1.0.50 6,655 8/21/2023
1.0.49 2,578 8/18/2023
1.0.48 2,453 8/17/2023
1.0.47 4,921 8/16/2023
1.0.46 7,678 8/10/2023
1.0.45 2,687 8/9/2023
1.0.44 4,703 8/8/2023
1.0.43 3,811 8/7/2023
1.0.42 4,066 8/4/2023
1.0.41 7,204 7/13/2023
1.0.40 4,993 7/11/2023
1.0.39 2,872 7/10/2023
1.0.38 3,824 7/7/2023
1.0.37 329 7/7/2023
1.0.36 10,369 6/30/2023
1.0.35 5,343 6/28/2023
1.0.34 5,663 6/27/2023
1.0.33 6,468 6/26/2023
1.0.32 3,768 6/23/2023
1.0.31 7,810 6/21/2023
1.0.30 7,993 6/15/2023
1.0.29 3,089 6/14/2023
1.0.28 8,573 6/9/2023
1.0.27 3,771 6/8/2023
1.0.26 4,681 6/7/2023
1.0.25 5,332 6/6/2023
1.0.24 350 6/6/2023
1.0.23 4,299 6/5/2023
1.0.22 14,850 5/30/2023
1.0.21 18,272 5/29/2023
1.0.20 6,255 5/26/2023
1.0.19 7,293 5/25/2023
1.0.18 7,706 5/24/2023
1.0.17 5,134 5/24/2023
1.0.16 1,440 5/23/2023
1.0.15 1,554 5/23/2023
1.0.12 2,693 5/22/2023
1.0.11 17,504 5/16/2023
1.0.10 14,268 4/20/2023
1.0.9 13,635 4/3/2023
1.0.8 1,193 4/3/2023
1.0.7 2,347 3/23/2023
1.0.5 724 3/13/2023
1.0.4 482 3/11/2023
1.0.3 407 3/11/2023
1.0.2 410 3/11/2023
1.0.1 455 3/11/2023