Soenneker.Utils.AsyncSingleton 2.1.247

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

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

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.275 4,555 6/1/2024
2.1.274 1,230 6/1/2024
2.1.273 755 6/1/2024
2.1.272 6,720 5/31/2024
2.1.271 4,206 5/29/2024
2.1.270 4,809 5/28/2024
2.1.269 2,689 5/27/2024
2.1.268 5,006 5/26/2024
2.1.267 4,927 5/26/2024
2.1.266 215 5/26/2024
2.1.265 1,797 5/25/2024
2.1.264 1,314 5/25/2024
2.1.263 1,189 5/25/2024
2.1.262 70 5/25/2024
2.1.261 968 5/25/2024
2.1.260 68 5/25/2024
2.1.259 3,493 5/25/2024
2.1.258 68 5/25/2024
2.1.257 6,325 5/23/2024
2.1.256 2,410 5/23/2024
2.1.255 1,748 5/22/2024
2.1.254 1,307 5/22/2024
2.1.253 532 5/22/2024
2.1.252 66 5/22/2024
2.1.251 66 5/22/2024
2.1.250 2,577 5/22/2024
2.1.249 6,599 5/18/2024
2.1.248 1,380 5/17/2024
2.1.247 2,323 5/17/2024
2.1.246 3,702 5/16/2024
2.1.245 922 5/15/2024
2.1.244 2,639 5/15/2024
2.1.243 5,352 5/12/2024
2.1.242 2,773 5/3/2024
2.1.241 3,343 4/29/2024
2.1.240 1,966 4/29/2024
2.1.239 3,747 4/28/2024
2.1.238 607 4/28/2024
2.1.237 698 4/28/2024
2.1.236 2,811 4/28/2024
2.1.235 385 4/28/2024
2.1.234 3,709 4/28/2024
2.1.233 798 4/28/2024
2.1.232 3,540 4/27/2024
2.1.231 70 4/27/2024
2.1.230 7,128 4/19/2024
2.1.229 4,386 4/18/2024
2.1.228 4,607 4/12/2024
2.1.227 724 4/12/2024
2.1.226 1,152 4/12/2024
2.1.225 972 4/12/2024
2.1.224 666 4/12/2024
2.1.223 968 4/12/2024
2.1.222 370 4/12/2024
2.1.221 77 4/12/2024
2.1.220 2,565 4/10/2024
2.1.219 9,854 4/10/2024
2.1.218 471 4/10/2024
2.1.217 5,439 4/2/2024
2.1.216 888 4/1/2024
2.1.215 5,187 3/29/2024
2.1.214 3,738 3/25/2024
2.1.213 435 3/25/2024
2.1.212 5,301 3/20/2024
2.1.211 3,641 3/19/2024
2.1.210 2,195 3/19/2024
2.1.209 2,387 3/18/2024
2.1.208 5,379 3/15/2024
2.1.207 3,672 3/13/2024
2.1.206 1,388 3/13/2024
2.1.205 1,822 3/13/2024
2.1.204 126 3/13/2024
2.1.203 108 3/13/2024
2.1.202 1,171 3/13/2024
2.1.201 115 3/13/2024
2.1.200 2,676 3/12/2024
2.1.199 3,385 3/12/2024
2.1.198 4,342 3/11/2024
2.1.197 3,031 3/11/2024
2.1.196 3,245 3/10/2024
2.1.195 4,291 3/8/2024
2.1.194 395 3/8/2024
2.1.193 3,072 3/8/2024
2.1.192 3,924 3/6/2024
2.1.191 3,968 3/4/2024
2.1.190 2,165 3/4/2024
2.1.189 4,582 3/2/2024
2.1.188 1,131 3/2/2024
2.1.187 1,398 3/2/2024
2.1.186 831 3/2/2024
2.1.185 545 3/2/2024
2.1.184 2,925 2/29/2024
2.1.183 981 2/29/2024
2.1.182 1,497 2/29/2024
2.1.181 2,899 2/26/2024
2.1.180 11,719 2/25/2024
2.1.179 1,390 2/25/2024
2.1.178 4,633 2/23/2024
2.1.177 4,456 2/22/2024
2.1.176 1,209 2/22/2024
2.1.175 1,422 2/21/2024
2.1.174 2,411 2/21/2024
2.1.173 2,158 2/21/2024
2.1.172 2,731 2/21/2024
2.1.171 1,141 2/21/2024
2.1.170 293 2/21/2024
2.1.169 2,597 2/21/2024
2.1.168 732 2/20/2024
2.1.167 164 2/20/2024
2.1.166 169 2/20/2024
2.1.165 3,330 2/20/2024
2.1.164 2,463 2/20/2024
2.1.163 2,406 2/20/2024
2.1.162 5,103 2/19/2024
2.1.161 4,071 2/17/2024
2.1.160 1,691 2/17/2024
2.1.159 1,148 2/16/2024
2.1.158 875 2/16/2024
2.1.157 1,463 2/16/2024
2.1.156 2,340 2/16/2024
2.1.155 2,623 2/16/2024
2.1.154 200 2/16/2024
2.1.153 1,291 2/16/2024
2.1.152 204 2/16/2024
2.1.151 192 2/16/2024
2.1.150 4,627 2/14/2024
2.1.149 1,961 2/13/2024
2.1.148 2,337 2/13/2024
2.1.147 2,800 2/13/2024
2.1.146 2,694 2/13/2024
2.1.145 3,728 2/12/2024
2.1.144 594 2/11/2024
2.1.143 4,093 2/11/2024
2.1.142 2,321 2/11/2024
2.1.141 4,781 2/10/2024
2.1.140 547 2/9/2024
2.1.139 4,434 2/9/2024
2.1.138 2,748 2/9/2024
2.1.137 733 2/8/2024
2.1.136 3,525 2/8/2024
2.1.135 1,420 2/8/2024
2.1.134 7,677 2/8/2024
2.1.133 263 2/8/2024
2.1.132 198 2/8/2024
2.1.131 4,034 2/7/2024
2.1.130 1,555 2/7/2024
2.1.129 2,706 2/7/2024
2.1.128 889 2/7/2024
2.1.127 806 2/6/2024
2.1.126 2,135 2/6/2024
2.1.125 236 2/6/2024
2.1.124 5,741 2/5/2024
2.1.123 3,777 2/4/2024
2.1.122 4,042 2/2/2024
2.1.121 4,888 1/31/2024
2.1.120 4,768 1/29/2024
2.1.119 2,787 1/29/2024
2.1.118 1,913 1/29/2024
2.1.117 3,152 1/28/2024
2.1.116 4,051 1/28/2024
2.1.115 2,354 1/28/2024
2.1.114 1,308 1/28/2024
2.1.113 1,941 1/27/2024
2.1.112 1,620 1/27/2024
2.1.111 4,295 1/27/2024
2.1.110 1,976 1/27/2024
2.1.109 5,215 1/27/2024
2.1.108 1,280 1/26/2024
2.1.107 1,670 1/26/2024
2.1.106 2,223 1/26/2024
2.1.105 3,965 1/26/2024
2.1.104 1,898 1/26/2024
2.1.103 993 1/26/2024
2.1.102 3,521 1/25/2024
2.1.101 2,733 1/25/2024
2.1.100 1,343 1/25/2024
2.1.99 4,702 1/25/2024
2.1.98 4,208 1/19/2024
2.1.97 4,562 1/15/2024
2.1.96 2,136 1/15/2024
2.1.95 1,596 1/15/2024
2.1.94 4,221 1/15/2024
2.1.93 4,313 1/15/2024
2.1.92 4,195 1/14/2024
2.1.91 5,155 1/13/2024
2.1.90 4,351 1/12/2024
2.1.89 4,214 1/11/2024
2.1.88 5,888 1/7/2024
2.1.87 4,624 1/5/2024
2.1.86 2,109 1/5/2024
2.1.85 2,578 1/5/2024
2.1.84 4,982 1/3/2024
2.1.83 3,038 1/1/2024
2.1.82 4,154 12/28/2023
2.1.81 1,687 12/28/2023
2.1.80 1,632 12/28/2023
2.1.79 3,750 12/27/2023
2.1.78 1,712 12/27/2023
2.1.77 259 12/27/2023
2.1.76 7,113 12/25/2023
2.1.75 3,914 12/25/2023
2.1.74 1,951 12/25/2023
2.1.73 536 12/25/2023
2.1.72 287 12/25/2023
2.1.71 5,458 12/24/2023
2.1.70 4,405 12/23/2023
2.1.69 2,285 12/23/2023
2.1.68 1,346 12/23/2023
2.1.67 3,255 12/23/2023
2.1.66 262 12/23/2023
2.1.65 6,409 12/19/2023
2.1.64 1,869 12/19/2023
2.1.63 4,443 12/12/2023
2.1.62 392 12/12/2023
2.1.61 2,237 12/11/2023
2.1.60 1,802 12/11/2023
2.1.59 1,078 12/11/2023
2.1.58 1,348 12/11/2023
2.1.57 662 12/10/2023
2.1.56 658 12/10/2023
2.1.55 1,557 12/10/2023
2.1.54 960 12/10/2023
2.1.53 6,838 12/10/2023
2.1.52 1,551 12/9/2023
2.1.51 884 12/9/2023
2.1.50 1,323 12/9/2023
2.1.49 2,094 12/9/2023
2.1.48 237 12/9/2023
2.1.47 967 12/9/2023
2.1.46 310 12/9/2023
2.1.45 2,459 12/9/2023
2.1.44 270 12/9/2023
2.1.43 3,695 12/9/2023
2.1.42 5,651 12/6/2023
2.1.41 1,042 12/6/2023
2.1.40 1,418 12/6/2023
2.1.39 3,262 12/5/2023
2.1.38 1,649 12/5/2023
2.1.37 954 12/5/2023
2.1.36 2,379 12/5/2023
2.1.35 258 12/5/2023
2.1.34 2,041 12/5/2023
2.1.33 269 12/5/2023
2.1.32 1,235 12/4/2023
2.1.31 1,348 12/4/2023
2.1.30 286 12/4/2023
2.1.29 7,254 12/4/2023
2.1.28 2,239 11/27/2023
2.1.27 1,088 11/26/2023
2.1.26 2,763 11/23/2023
2.1.25 2,348 11/23/2023
2.1.24 2,861 11/23/2023
2.1.23 271 11/23/2023
2.1.22 5,650 11/20/2023
2.1.21 2,751 11/20/2023
2.1.20 4,237 11/19/2023
2.1.19 2,446 11/19/2023
2.1.18 3,366 11/19/2023
2.1.17 910 11/18/2023
2.1.16 4,233 11/18/2023
2.1.15 1,128 11/18/2023
2.1.14 2,795 11/18/2023
2.1.13 693 11/18/2023
2.1.12 2,856 11/17/2023
2.1.11 2,389 11/17/2023
2.1.10 1,641 11/17/2023
2.1.9 322 11/17/2023
2.1.8 2,926 11/17/2023
2.1.7 1,575 11/17/2023
2.1.6 1,973 11/17/2023
2.1.5 1,179 11/17/2023
2.1.4 461 11/17/2023
2.1.3 2,566 11/16/2023
2.0.78 916 11/15/2023
2.0.77 285 11/15/2023
2.0.76 2,295 11/15/2023
2.0.2 291 11/16/2023
2.0.1 258 11/16/2023
1.0.75 3,351 11/13/2023
1.0.74 4,977 11/10/2023
1.0.73 4,023 11/9/2023
1.0.72 2,700 11/8/2023
1.0.71 4,201 11/7/2023
1.0.70 2,025 11/6/2023
1.0.69 2,571 11/3/2023
1.0.68 4,849 11/2/2023
1.0.67 2,699 11/1/2023
1.0.66 8,630 10/26/2023
1.0.65 5,488 10/19/2023
1.0.64 2,501 10/18/2023
1.0.63 2,299 10/17/2023
1.0.62 2,787 10/16/2023
1.0.61 5,427 10/13/2023
1.0.60 3,137 10/12/2023
1.0.59 9,298 9/18/2023
1.0.58 280 9/18/2023
1.0.57 6,517 9/14/2023
1.0.56 5,923 8/31/2023
1.0.55 3,179 8/30/2023
1.0.54 2,560 8/29/2023
1.0.53 2,519 8/28/2023
1.0.52 4,994 8/25/2023
1.0.51 2,697 8/24/2023
1.0.50 6,658 8/21/2023
1.0.49 2,581 8/18/2023
1.0.48 2,456 8/17/2023
1.0.47 4,924 8/16/2023
1.0.46 7,681 8/10/2023
1.0.45 2,690 8/9/2023
1.0.44 4,711 8/8/2023
1.0.43 3,819 8/7/2023
1.0.42 4,069 8/4/2023
1.0.41 7,208 7/13/2023
1.0.40 5,001 7/11/2023
1.0.39 2,875 7/10/2023
1.0.38 3,827 7/7/2023
1.0.37 332 7/7/2023
1.0.36 10,378 6/30/2023
1.0.35 5,346 6/28/2023
1.0.34 5,666 6/27/2023
1.0.33 6,476 6/26/2023
1.0.32 3,771 6/23/2023
1.0.31 7,828 6/21/2023
1.0.30 7,996 6/15/2023
1.0.29 3,092 6/14/2023
1.0.28 8,576 6/9/2023
1.0.27 3,774 6/8/2023
1.0.26 4,684 6/7/2023
1.0.25 5,335 6/6/2023
1.0.24 354 6/6/2023
1.0.23 4,302 6/5/2023
1.0.22 14,854 5/30/2023
1.0.21 18,277 5/29/2023
1.0.20 6,258 5/26/2023
1.0.19 7,301 5/25/2023
1.0.18 7,714 5/24/2023
1.0.17 5,137 5/24/2023
1.0.16 1,443 5/23/2023
1.0.15 1,557 5/23/2023
1.0.12 2,704 5/22/2023
1.0.11 17,512 5/16/2023
1.0.10 14,272 4/20/2023
1.0.9 13,646 4/3/2023
1.0.8 1,196 4/3/2023
1.0.7 2,359 3/23/2023
1.0.5 727 3/13/2023
1.0.4 485 3/11/2023
1.0.3 410 3/11/2023
1.0.2 413 3/11/2023
1.0.1 458 3/11/2023