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
There is a newer version of this package available.
See the version list below for details.
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.242 24 5/3/2024
2.1.241 2,539 4/29/2024
2.1.240 1,703 4/29/2024
2.1.239 3,598 4/28/2024
2.1.238 601 4/28/2024
2.1.237 692 4/28/2024
2.1.236 2,802 4/28/2024
2.1.235 379 4/28/2024
2.1.234 3,634 4/28/2024
2.1.233 792 4/28/2024
2.1.232 3,529 4/27/2024
2.1.231 64 4/27/2024
2.1.230 7,125 4/19/2024
2.1.229 4,383 4/18/2024
2.1.228 4,598 4/12/2024
2.1.227 719 4/12/2024
2.1.226 1,149 4/12/2024
2.1.225 962 4/12/2024
2.1.224 663 4/12/2024
2.1.223 965 4/12/2024
2.1.222 367 4/12/2024
2.1.221 74 4/12/2024
2.1.220 2,556 4/10/2024
2.1.219 9,826 4/10/2024
2.1.218 468 4/10/2024
2.1.217 5,430 4/2/2024
2.1.216 882 4/1/2024
2.1.215 5,180 3/29/2024
2.1.214 3,735 3/25/2024
2.1.213 429 3/25/2024
2.1.212 5,290 3/20/2024
2.1.211 3,630 3/19/2024
2.1.210 2,188 3/19/2024
2.1.209 2,377 3/18/2024
2.1.208 5,368 3/15/2024
2.1.207 3,666 3/13/2024
2.1.206 1,386 3/13/2024
2.1.205 1,819 3/13/2024
2.1.204 123 3/13/2024
2.1.203 105 3/13/2024
2.1.202 1,168 3/13/2024
2.1.201 112 3/13/2024
2.1.200 2,672 3/12/2024
2.1.199 3,382 3/12/2024
2.1.198 4,339 3/11/2024
2.1.197 3,021 3/11/2024
2.1.196 3,242 3/10/2024
2.1.195 4,285 3/8/2024
2.1.194 392 3/8/2024
2.1.193 3,069 3/8/2024
2.1.192 3,918 3/6/2024
2.1.191 3,965 3/4/2024
2.1.190 2,162 3/4/2024
2.1.189 4,579 3/2/2024
2.1.188 1,128 3/2/2024
2.1.187 1,395 3/2/2024
2.1.186 828 3/2/2024
2.1.185 542 3/2/2024
2.1.184 2,898 2/29/2024
2.1.183 978 2/29/2024
2.1.182 1,495 2/29/2024
2.1.181 2,896 2/26/2024
2.1.180 11,709 2/25/2024
2.1.179 1,384 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,728 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,460 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,132 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,190 1/14/2024
2.1.91 5,150 1/13/2024
2.1.90 4,348 1/12/2024
2.1.89 4,211 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,980 1/3/2024
2.1.83 3,036 1/1/2024
2.1.82 4,151 12/28/2023
2.1.81 1,683 12/28/2023
2.1.80 1,630 12/28/2023
2.1.79 3,745 12/27/2023
2.1.78 1,696 12/27/2023
2.1.77 257 12/27/2023
2.1.76 7,107 12/25/2023
2.1.75 3,913 12/25/2023
2.1.74 1,950 12/25/2023
2.1.73 535 12/25/2023
2.1.72 286 12/25/2023
2.1.71 5,457 12/24/2023
2.1.70 4,404 12/23/2023
2.1.69 2,284 12/23/2023
2.1.68 1,345 12/23/2023
2.1.67 3,252 12/23/2023
2.1.66 261 12/23/2023
2.1.65 6,408 12/19/2023
2.1.64 1,868 12/19/2023
2.1.63 4,441 12/12/2023
2.1.62 390 12/12/2023
2.1.61 2,235 12/11/2023
2.1.60 1,797 12/11/2023
2.1.59 1,076 12/11/2023
2.1.58 1,347 12/11/2023
2.1.57 661 12/10/2023
2.1.56 657 12/10/2023
2.1.55 1,556 12/10/2023
2.1.54 959 12/10/2023
2.1.53 6,834 12/10/2023
2.1.52 1,550 12/9/2023
2.1.51 883 12/9/2023
2.1.50 1,322 12/9/2023
2.1.49 2,093 12/9/2023
2.1.48 236 12/9/2023
2.1.47 966 12/9/2023
2.1.46 309 12/9/2023
2.1.45 2,458 12/9/2023
2.1.44 269 12/9/2023
2.1.43 3,694 12/9/2023
2.1.42 5,643 12/6/2023
2.1.41 1,041 12/6/2023
2.1.40 1,417 12/6/2023
2.1.39 3,261 12/5/2023
2.1.38 1,648 12/5/2023
2.1.37 953 12/5/2023
2.1.36 2,378 12/5/2023
2.1.35 257 12/5/2023
2.1.34 2,040 12/5/2023
2.1.33 268 12/5/2023
2.1.32 1,234 12/4/2023
2.1.31 1,347 12/4/2023
2.1.30 285 12/4/2023
2.1.29 7,247 12/4/2023
2.1.28 2,237 11/27/2023
2.1.27 1,087 11/26/2023
2.1.26 2,758 11/23/2023
2.1.25 2,347 11/23/2023
2.1.24 2,860 11/23/2023
2.1.23 270 11/23/2023
2.1.22 5,649 11/20/2023
2.1.21 2,750 11/20/2023
2.1.20 4,236 11/19/2023
2.1.19 2,445 11/19/2023
2.1.18 3,365 11/19/2023
2.1.17 909 11/18/2023
2.1.16 4,232 11/18/2023
2.1.15 1,124 11/18/2023
2.1.14 2,792 11/18/2023
2.1.13 692 11/18/2023
2.1.12 2,851 11/17/2023
2.1.11 2,384 11/17/2023
2.1.10 1,640 11/17/2023
2.1.9 321 11/17/2023
2.1.8 2,925 11/17/2023
2.1.7 1,574 11/17/2023
2.1.6 1,972 11/17/2023
2.1.5 1,178 11/17/2023
2.1.4 460 11/17/2023
2.1.3 2,565 11/16/2023
2.0.78 912 11/15/2023
2.0.77 284 11/15/2023
2.0.76 2,294 11/15/2023
2.0.2 290 11/16/2023
2.0.1 256 11/16/2023
1.0.75 3,349 11/13/2023
1.0.74 4,974 11/10/2023
1.0.73 4,022 11/9/2023
1.0.72 2,689 11/8/2023
1.0.71 4,200 11/7/2023
1.0.70 2,024 11/6/2023
1.0.69 2,570 11/3/2023
1.0.68 4,848 11/2/2023
1.0.67 2,698 11/1/2023
1.0.66 8,628 10/26/2023
1.0.65 5,487 10/19/2023
1.0.64 2,500 10/18/2023
1.0.63 2,298 10/17/2023
1.0.62 2,786 10/16/2023
1.0.61 5,421 10/13/2023
1.0.60 3,136 10/12/2023
1.0.59 9,296 9/18/2023
1.0.58 279 9/18/2023
1.0.57 6,516 9/14/2023
1.0.56 5,921 8/31/2023
1.0.55 3,178 8/30/2023
1.0.54 2,558 8/29/2023
1.0.53 2,518 8/28/2023
1.0.52 4,993 8/25/2023
1.0.51 2,696 8/24/2023
1.0.50 6,657 8/21/2023
1.0.49 2,580 8/18/2023
1.0.48 2,455 8/17/2023
1.0.47 4,923 8/16/2023
1.0.46 7,680 8/10/2023
1.0.45 2,689 8/9/2023
1.0.44 4,705 8/8/2023
1.0.43 3,813 8/7/2023
1.0.42 4,068 8/4/2023
1.0.41 7,206 7/13/2023
1.0.40 4,995 7/11/2023
1.0.39 2,874 7/10/2023
1.0.38 3,826 7/7/2023
1.0.37 331 7/7/2023
1.0.36 10,371 6/30/2023
1.0.35 5,345 6/28/2023
1.0.34 5,665 6/27/2023
1.0.33 6,470 6/26/2023
1.0.32 3,770 6/23/2023
1.0.31 7,812 6/21/2023
1.0.30 7,995 6/15/2023
1.0.29 3,091 6/14/2023
1.0.28 8,575 6/9/2023
1.0.27 3,773 6/8/2023
1.0.26 4,683 6/7/2023
1.0.25 5,334 6/6/2023
1.0.24 352 6/6/2023
1.0.23 4,301 6/5/2023
1.0.22 14,852 5/30/2023
1.0.21 18,274 5/29/2023
1.0.20 6,257 5/26/2023
1.0.19 7,295 5/25/2023
1.0.18 7,708 5/24/2023
1.0.17 5,136 5/24/2023
1.0.16 1,442 5/23/2023
1.0.15 1,556 5/23/2023
1.0.12 2,695 5/22/2023
1.0.11 17,511 5/16/2023
1.0.10 14,270 4/20/2023
1.0.9 13,642 4/3/2023
1.0.8 1,195 4/3/2023
1.0.7 2,350 3/23/2023
1.0.5 726 3/13/2023
1.0.4 484 3/11/2023
1.0.3 409 3/11/2023
1.0.2 412 3/11/2023
1.0.1 457 3/11/2023