Soenneker.Utils.SingletonDictionary 2.1.255

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.SingletonDictionary --version 2.1.255
NuGet\Install-Package Soenneker.Utils.SingletonDictionary -Version 2.1.255
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.SingletonDictionary" Version="2.1.255" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Soenneker.Utils.SingletonDictionary --version 2.1.255
#r "nuget: Soenneker.Utils.SingletonDictionary, 2.1.255"
#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.SingletonDictionary as a Cake Addin
#addin nuget:?package=Soenneker.Utils.SingletonDictionary&version=2.1.255

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

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.SingletonDictionary

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

Installation

dotnet add package Soenneker.Utils.SingletonDictionary

Example

Below is a long-living HttpClient implementation using SingletonDictionary with different settings. It guarantees only one instance of a particular key is instantiated due to the locking.

public class HttpRequester : IDisposable, IAsyncDisposable
{
    private readonly SingletonDictionary<HttpClient> _clients;

    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.
        _clients = new SingletonDictionary<HttpClient>((args) =>
        {
            var socketsHandler = new SocketsHttpHandler
            {
                PooledConnectionLifetime = TimeSpan.FromMinutes(10),
                MaxConnectionsPerServer = 10
            };

            HttpClient client = new HttpClient(socketsHandler);
            client.Timeout = TimeSpan.FromSeconds((int)args[0]);

            return client;
        });
    }

    public async ValueTask Get()
    {
        // retrieve the singleton async, thus not blocking the calling thread
        await (await _client.Get("100", 100)).GetAsync("https://google.com");
    }

    // Disposal is not necessary for AsyncSingleton unless the type used is IDisposable/IAsyncDisposable
    public ValueTask DisposeAsync()
    {
        GC.SuppressFinalize(false);

        return _client.DisposeAsync();
    }

    public void Dispose()
    {
        GC.SuppressFinalize(false);
        
        _client.Dispose();
    }
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Soenneker.Utils.SingletonDictionary:

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

A utility library for storing Azure Cosmos databases

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

A utility library that holds Azure Service senders

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

Providing thread-safe singleton HttpClients

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

An async thread-safe singleton for Google OAuth credentials

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.267 18 5/3/2024
2.1.266 481 4/30/2024
2.1.265 1,043 4/29/2024
2.1.264 1,267 4/29/2024
2.1.263 1,818 4/28/2024
2.1.262 1,035 4/28/2024
2.1.261 773 4/28/2024
2.1.260 1,268 4/28/2024
2.1.259 610 4/28/2024
2.1.258 61 4/28/2024
2.1.257 3,030 4/27/2024
2.1.256 67 4/27/2024
2.1.255 3,190 4/19/2024
2.1.254 2,931 4/18/2024
2.1.253 2,480 4/12/2024
2.1.252 782 4/12/2024
2.1.251 506 4/12/2024
2.1.250 597 4/12/2024
2.1.249 115 4/12/2024
2.1.248 58 4/12/2024
2.1.247 699 4/12/2024
2.1.246 199 4/12/2024
2.1.245 1,164 4/11/2024
2.1.244 2,607 4/10/2024
2.1.243 810 4/9/2024
2.1.242 2,228 4/2/2024
2.1.241 626 4/1/2024
2.1.240 1,446 3/29/2024
2.1.239 1,308 3/25/2024
2.1.238 189 3/25/2024
2.1.237 2,364 3/20/2024
2.1.236 1,517 3/19/2024
2.1.235 379 3/19/2024
2.1.234 1,645 3/18/2024
2.1.233 1,025 3/18/2024
2.1.232 1,003 3/15/2024
2.1.231 1,686 3/13/2024
2.1.230 799 3/13/2024
2.1.229 437 3/13/2024
2.1.228 547 3/13/2024
2.1.227 80 3/13/2024
2.1.226 371 3/13/2024
2.1.225 88 3/13/2024
2.1.224 79 3/13/2024
2.1.223 1,139 3/12/2024
2.1.222 1,995 3/11/2024
2.1.221 1,719 3/11/2024
2.1.220 1,161 3/10/2024
2.1.219 1,359 3/8/2024
2.1.218 755 3/8/2024
2.1.217 1,111 3/8/2024
2.1.216 1,500 3/6/2024
2.1.215 1,468 3/4/2024
2.1.214 1,005 3/4/2024
2.1.213 1,838 3/2/2024
2.1.212 840 3/2/2024
2.1.211 268 3/2/2024
2.1.210 222 3/2/2024
2.1.209 290 3/2/2024
2.1.208 2,539 2/29/2024
2.1.207 447 2/29/2024
2.1.206 220 2/29/2024
2.1.205 2,459 2/26/2024
2.1.204 1,085 2/25/2024
2.1.203 1,965 2/23/2024
2.1.202 1,431 2/22/2024
2.1.201 706 2/22/2024
2.1.200 284 2/21/2024
2.1.199 895 2/21/2024
2.1.198 200 2/21/2024
2.1.197 601 2/21/2024
2.1.196 90 2/21/2024
2.1.195 852 2/21/2024
2.1.194 292 2/21/2024
2.1.193 81 2/21/2024
2.1.192 81 2/21/2024
2.1.191 447 2/21/2024
2.1.190 64 2/21/2024
2.1.189 1,906 2/20/2024
2.1.188 555 2/20/2024
2.1.187 471 2/20/2024
2.1.186 482 2/20/2024
2.1.185 1,541 2/19/2024
2.1.184 1,369 2/17/2024
2.1.183 638 2/16/2024
2.1.182 654 2/16/2024
2.1.181 934 2/16/2024
2.1.180 67 2/16/2024
2.1.179 429 2/16/2024
2.1.178 62 2/16/2024
2.1.177 77 2/16/2024
2.1.176 389 2/16/2024
2.1.175 64 2/16/2024
2.1.174 2,474 2/13/2024
2.1.173 1,001 2/13/2024
2.1.172 811 2/13/2024
2.1.171 307 2/13/2024
2.1.170 449 2/13/2024
2.1.169 1,438 2/12/2024
2.1.168 389 2/11/2024
2.1.167 1,151 2/11/2024
2.1.166 645 2/11/2024
2.1.165 2,006 2/10/2024
2.1.164 408 2/9/2024
2.1.163 66 2/9/2024
2.1.162 1,132 2/9/2024
2.1.161 1,218 2/9/2024
2.1.160 253 2/8/2024
2.1.159 879 2/8/2024
2.1.158 639 2/8/2024
2.1.157 1,071 2/8/2024
2.1.156 68 2/8/2024
2.1.155 1,394 2/7/2024
2.1.154 305 2/7/2024
2.1.153 446 2/7/2024
2.1.152 917 2/7/2024
2.1.151 262 2/6/2024
2.1.150 78 2/6/2024
2.1.149 63 2/6/2024
2.1.148 2,084 2/5/2024
2.1.147 1,113 2/4/2024
2.1.146 1,516 2/2/2024
2.1.145 1,475 1/31/2024
2.1.144 1,624 1/29/2024
2.1.143 1,024 1/29/2024
2.1.142 248 1/29/2024
2.1.141 1,142 1/28/2024
2.1.140 332 1/28/2024
2.1.139 207 1/28/2024
2.1.138 409 1/28/2024
2.1.137 1,426 1/28/2024
2.1.136 678 1/28/2024
2.1.135 192 1/27/2024
2.1.134 712 1/27/2024
2.1.133 780 1/27/2024
2.1.132 877 1/27/2024
2.1.131 93 1/27/2024
2.1.130 548 1/27/2024
2.1.129 746 1/26/2024
2.1.128 135 1/26/2024
2.1.127 676 1/26/2024
2.1.126 793 1/26/2024
2.1.125 1,262 1/26/2024
2.1.124 606 1/25/2024
2.1.123 873 1/25/2024
2.1.122 339 1/25/2024
2.1.121 712 1/25/2024
2.1.120 394 1/25/2024
2.1.119 1,918 1/19/2024
2.1.118 1,712 1/15/2024
2.1.117 384 1/15/2024
2.1.116 893 1/15/2024
2.1.115 80 1/15/2024
2.1.114 427 1/15/2024
2.1.113 1,042 1/15/2024
2.1.112 1,996 1/14/2024
2.1.111 1,220 1/13/2024
2.1.110 1,466 1/12/2024
2.1.109 1,579 1/11/2024
2.1.108 2,081 1/7/2024
2.1.107 1,695 1/5/2024
2.1.106 330 1/5/2024
2.1.105 91 1/5/2024
2.1.104 85 1/5/2024
2.1.103 1,154 1/5/2024
2.1.102 98 1/5/2024
2.1.101 2,113 1/1/2024
2.1.100 1,717 12/28/2023
2.1.99 555 12/28/2023
2.1.98 353 12/28/2023
2.1.97 94 12/28/2023
2.1.96 92 12/28/2023
2.1.95 551 12/27/2023
2.1.94 83 12/27/2023
2.1.93 337 12/27/2023
2.1.92 78 12/27/2023
2.1.91 84 12/27/2023
2.1.90 1,579 12/25/2023
2.1.89 258 12/25/2023
2.1.88 477 12/25/2023
2.1.87 84 12/25/2023
2.1.86 441 12/25/2023
2.1.85 91 12/25/2023
2.1.84 380 12/25/2023
2.1.83 83 12/25/2023
2.1.82 1,112 12/24/2023
2.1.81 774 12/23/2023
2.1.80 542 12/23/2023
2.1.79 230 12/23/2023
2.1.78 399 12/23/2023
2.1.77 90 12/23/2023
2.1.76 80 12/23/2023
2.1.75 738 12/23/2023
2.1.74 79 12/23/2023
2.1.73 963 12/19/2023
2.1.72 151 12/19/2023
2.1.71 2,171 12/11/2023
2.1.70 508 12/10/2023
2.1.69 90 12/10/2023
2.1.68 365 12/10/2023
2.1.67 989 12/10/2023
2.1.66 244 12/9/2023
2.1.65 260 12/9/2023
2.1.64 204 12/9/2023
2.1.63 86 12/9/2023
2.1.62 194 12/9/2023
2.1.61 137 12/9/2023
2.1.60 85 12/9/2023
2.1.59 756 12/9/2023
2.1.58 88 12/9/2023
2.1.57 1,066 12/6/2023
2.1.56 247 12/6/2023
2.1.55 138 12/6/2023
2.1.54 200 12/6/2023
2.1.53 611 12/5/2023
2.1.52 254 12/5/2023
2.1.51 238 12/5/2023
2.1.50 248 12/5/2023
2.1.49 90 12/5/2023
2.1.48 250 12/5/2023
2.1.47 194 12/5/2023
2.1.46 92 12/4/2023
2.1.45 93 12/4/2023
2.1.44 250 12/4/2023
2.1.43 100 12/4/2023
2.1.42 591 12/4/2023
2.1.41 79 12/4/2023
2.1.40 796 11/27/2023
2.1.39 320 11/26/2023
2.1.38 128 11/26/2023
2.1.37 353 11/23/2023
2.1.36 431 11/23/2023
2.1.35 424 11/23/2023
2.1.34 91 11/23/2023
2.1.33 208 11/23/2023
2.1.32 82 11/23/2023
2.1.31 704 11/20/2023
2.1.30 604 11/20/2023
2.1.29 482 11/19/2023
2.1.28 145 11/19/2023
2.1.27 307 11/19/2023
2.1.26 288 11/19/2023
2.1.25 284 11/19/2023
2.1.24 85 11/19/2023
2.1.23 149 11/18/2023
2.1.22 617 11/18/2023
2.1.21 233 11/18/2023
2.1.20 325 11/18/2023
2.1.19 92 11/18/2023
2.1.18 178 11/18/2023
2.1.17 92 11/18/2023
2.1.16 352 11/17/2023
2.1.15 299 11/17/2023
2.1.14 90 11/17/2023
2.1.13 294 11/17/2023
2.1.12 186 11/17/2023
2.1.11 286 11/17/2023
2.1.10 84 11/17/2023
2.1.9 282 11/17/2023
2.1.8 88 11/17/2023
2.1.7 94 11/17/2023
2.1.6 218 11/17/2023
2.1.5 195 11/16/2023
2.0.101 1,255 11/15/2023
2.0.100 81 11/15/2023
2.0.99 87 11/15/2023
2.0.4 89 11/16/2023
2.0.3 91 11/16/2023
2.0.2 89 11/16/2023
2.0.1 87 11/16/2023
1.0.98 398 11/14/2023
1.0.97 529 11/13/2023
1.0.96 81 11/13/2023
1.0.95 425 11/10/2023
1.0.94 83 11/10/2023
1.0.93 564 11/9/2023
1.0.92 86 11/9/2023
1.0.91 654 11/7/2023
1.0.90 80 11/7/2023
1.0.89 347 11/6/2023
1.0.88 85 11/6/2023
1.0.87 440 11/3/2023
1.0.86 96 11/3/2023
1.0.85 569 11/2/2023
1.0.84 85 11/2/2023
1.0.83 436 11/1/2023
1.0.82 978 10/26/2023
1.0.81 869 10/19/2023
1.0.80 98 10/19/2023
1.0.79 530 10/18/2023
1.0.78 106 10/18/2023
1.0.77 484 10/17/2023
1.0.76 100 10/17/2023
1.0.75 450 10/16/2023
1.0.74 101 10/16/2023
1.0.73 490 10/13/2023
1.0.72 242 10/12/2023
1.0.71 1,222 9/20/2023
1.0.70 416 9/19/2023
1.0.69 444 9/18/2023
1.0.68 98 9/18/2023
1.0.67 613 9/14/2023
1.0.66 1,053 8/31/2023
1.0.65 110 8/31/2023
1.0.64 540 8/30/2023
1.0.63 113 8/30/2023
1.0.62 112 8/30/2023
1.0.61 616 8/28/2023
1.0.60 504 8/25/2023
1.0.59 108 8/25/2023
1.0.58 343 8/24/2023
1.0.57 976 8/21/2023
1.0.56 542 8/18/2023
1.0.55 518 8/17/2023
1.0.54 117 8/17/2023
1.0.53 1,384 8/10/2023
1.0.52 416 8/9/2023
1.0.51 506 8/8/2023
1.0.50 476 8/7/2023
1.0.49 134 8/7/2023
1.0.48 1,738 7/13/2023
1.0.47 661 7/11/2023
1.0.46 556 7/10/2023
1.0.45 525 7/7/2023
1.0.44 129 7/7/2023
1.0.43 1,503 6/30/2023
1.0.42 792 6/29/2023
1.0.41 457 6/28/2023
1.0.40 1,148 6/26/2023
1.0.39 546 6/23/2023
1.0.38 795 6/21/2023
1.0.37 1,053 6/15/2023
1.0.36 345 6/14/2023
1.0.35 1,327 6/9/2023
1.0.34 649 6/8/2023
1.0.33 1,246 6/7/2023
1.0.32 126 6/7/2023
1.0.31 955 6/6/2023
1.0.30 902 6/5/2023
1.0.29 1,104 6/2/2023
1.0.28 116 6/2/2023
1.0.27 1,021 6/1/2023
1.0.26 484 5/31/2023
1.0.25 372 5/31/2023
1.0.24 118 5/31/2023
1.0.23 1,215 5/30/2023
1.0.22 1,261 5/26/2023
1.0.21 540 5/25/2023
1.0.20 114 5/25/2023
1.0.19 671 5/24/2023
1.0.18 116 5/24/2023
1.0.17 344 5/23/2023
1.0.13 1,174 5/22/2023
1.0.12 961 5/18/2023
1.0.11 461 5/17/2023
1.0.10 1,303 5/1/2023
1.0.9 834 4/25/2023
1.0.8 395 4/24/2023
1.0.7 858 4/21/2023
1.0.6 1,652 4/13/2023
1.0.5 489 4/12/2023
1.0.4 825 4/8/2023
1.0.3 153 4/8/2023
1.0.2 484 4/8/2023
1.0.1 150 4/8/2023