Soenneker.Utils.SingletonDictionary 2.1.253

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.SingletonDictionary --version 2.1.253
NuGet\Install-Package Soenneker.Utils.SingletonDictionary -Version 2.1.253
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.253" />
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.253
#r "nuget: Soenneker.Utils.SingletonDictionary, 2.1.253"
#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.253

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

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.253 1,127 4/12/2024
2.1.252 689 4/12/2024
2.1.251 401 4/12/2024
2.1.250 505 4/12/2024
2.1.249 76 4/12/2024
2.1.248 43 4/12/2024
2.1.247 586 4/12/2024
2.1.246 152 4/12/2024
2.1.245 855 4/11/2024
2.1.244 2,072 4/10/2024
2.1.243 727 4/9/2024
2.1.242 2,143 4/2/2024
2.1.241 625 4/1/2024
2.1.240 1,445 3/29/2024
2.1.239 1,301 3/25/2024
2.1.238 185 3/25/2024
2.1.237 2,362 3/20/2024
2.1.236 1,515 3/19/2024
2.1.235 377 3/19/2024
2.1.234 1,643 3/18/2024
2.1.233 1,023 3/18/2024
2.1.232 1,001 3/15/2024
2.1.231 1,684 3/13/2024
2.1.230 797 3/13/2024
2.1.229 435 3/13/2024
2.1.228 545 3/13/2024
2.1.227 78 3/13/2024
2.1.226 369 3/13/2024
2.1.225 86 3/13/2024
2.1.224 77 3/13/2024
2.1.223 1,137 3/12/2024
2.1.222 1,993 3/11/2024
2.1.221 1,717 3/11/2024
2.1.220 1,159 3/10/2024
2.1.219 1,357 3/8/2024
2.1.218 753 3/8/2024
2.1.217 1,109 3/8/2024
2.1.216 1,498 3/6/2024
2.1.215 1,466 3/4/2024
2.1.214 1,000 3/4/2024
2.1.213 1,836 3/2/2024
2.1.212 835 3/2/2024
2.1.211 266 3/2/2024
2.1.210 220 3/2/2024
2.1.209 288 3/2/2024
2.1.208 2,535 2/29/2024
2.1.207 445 2/29/2024
2.1.206 218 2/29/2024
2.1.205 2,457 2/26/2024
2.1.204 1,083 2/25/2024
2.1.203 1,964 2/23/2024
2.1.202 1,430 2/22/2024
2.1.201 705 2/22/2024
2.1.200 283 2/21/2024
2.1.199 894 2/21/2024
2.1.198 199 2/21/2024
2.1.197 600 2/21/2024
2.1.196 89 2/21/2024
2.1.195 851 2/21/2024
2.1.194 291 2/21/2024
2.1.193 80 2/21/2024
2.1.192 80 2/21/2024
2.1.191 446 2/21/2024
2.1.190 63 2/21/2024
2.1.189 1,902 2/20/2024
2.1.188 554 2/20/2024
2.1.187 470 2/20/2024
2.1.186 481 2/20/2024
2.1.185 1,540 2/19/2024
2.1.184 1,368 2/17/2024
2.1.183 637 2/16/2024
2.1.182 653 2/16/2024
2.1.181 933 2/16/2024
2.1.180 66 2/16/2024
2.1.179 428 2/16/2024
2.1.178 61 2/16/2024
2.1.177 76 2/16/2024
2.1.176 388 2/16/2024
2.1.175 63 2/16/2024
2.1.174 2,470 2/13/2024
2.1.173 1,000 2/13/2024
2.1.172 810 2/13/2024
2.1.171 306 2/13/2024
2.1.170 448 2/13/2024
2.1.169 1,437 2/12/2024
2.1.168 388 2/11/2024
2.1.167 1,150 2/11/2024
2.1.166 644 2/11/2024
2.1.165 2,005 2/10/2024
2.1.164 407 2/9/2024
2.1.163 65 2/9/2024
2.1.162 1,131 2/9/2024
2.1.161 1,217 2/9/2024
2.1.160 252 2/8/2024
2.1.159 878 2/8/2024
2.1.158 638 2/8/2024
2.1.157 1,068 2/8/2024
2.1.156 67 2/8/2024
2.1.155 1,393 2/7/2024
2.1.154 304 2/7/2024
2.1.153 442 2/7/2024
2.1.152 916 2/7/2024
2.1.151 261 2/6/2024
2.1.150 77 2/6/2024
2.1.149 62 2/6/2024
2.1.148 2,083 2/5/2024
2.1.147 1,112 2/4/2024
2.1.146 1,515 2/2/2024
2.1.145 1,474 1/31/2024
2.1.144 1,623 1/29/2024
2.1.143 1,023 1/29/2024
2.1.142 247 1/29/2024
2.1.141 1,141 1/28/2024
2.1.140 331 1/28/2024
2.1.139 206 1/28/2024
2.1.138 408 1/28/2024
2.1.137 1,425 1/28/2024
2.1.136 677 1/28/2024
2.1.135 191 1/27/2024
2.1.134 711 1/27/2024
2.1.133 779 1/27/2024
2.1.132 876 1/27/2024
2.1.131 92 1/27/2024
2.1.130 547 1/27/2024
2.1.129 745 1/26/2024
2.1.128 134 1/26/2024
2.1.127 675 1/26/2024
2.1.126 792 1/26/2024
2.1.125 1,260 1/26/2024
2.1.124 604 1/25/2024
2.1.123 871 1/25/2024
2.1.122 337 1/25/2024
2.1.121 711 1/25/2024
2.1.120 392 1/25/2024
2.1.119 1,914 1/19/2024
2.1.118 1,708 1/15/2024
2.1.117 382 1/15/2024
2.1.116 889 1/15/2024
2.1.115 78 1/15/2024
2.1.114 425 1/15/2024
2.1.113 1,040 1/15/2024
2.1.112 1,988 1/14/2024
2.1.111 1,216 1/13/2024
2.1.110 1,462 1/12/2024
2.1.109 1,571 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,111 1/1/2024
2.1.100 1,715 12/28/2023
2.1.99 553 12/28/2023
2.1.98 351 12/28/2023
2.1.97 92 12/28/2023
2.1.96 90 12/28/2023
2.1.95 549 12/27/2023
2.1.94 81 12/27/2023
2.1.93 335 12/27/2023
2.1.92 76 12/27/2023
2.1.91 82 12/27/2023
2.1.90 1,577 12/25/2023
2.1.89 255 12/25/2023
2.1.88 475 12/25/2023
2.1.87 82 12/25/2023
2.1.86 439 12/25/2023
2.1.85 89 12/25/2023
2.1.84 378 12/25/2023
2.1.83 81 12/25/2023
2.1.82 1,110 12/24/2023
2.1.81 772 12/23/2023
2.1.80 540 12/23/2023
2.1.79 228 12/23/2023
2.1.78 393 12/23/2023
2.1.77 88 12/23/2023
2.1.76 78 12/23/2023
2.1.75 736 12/23/2023
2.1.74 77 12/23/2023
2.1.73 958 12/19/2023
2.1.72 149 12/19/2023
2.1.71 2,165 12/11/2023
2.1.70 506 12/10/2023
2.1.69 88 12/10/2023
2.1.68 363 12/10/2023
2.1.67 987 12/10/2023
2.1.66 242 12/9/2023
2.1.65 258 12/9/2023
2.1.64 202 12/9/2023
2.1.63 84 12/9/2023
2.1.62 191 12/9/2023
2.1.61 134 12/9/2023
2.1.60 82 12/9/2023
2.1.59 753 12/9/2023
2.1.58 83 12/9/2023
2.1.57 1,061 12/6/2023
2.1.56 242 12/6/2023
2.1.55 133 12/6/2023
2.1.54 196 12/6/2023
2.1.53 607 12/5/2023
2.1.52 251 12/5/2023
2.1.51 235 12/5/2023
2.1.50 245 12/5/2023
2.1.49 87 12/5/2023
2.1.48 248 12/5/2023
2.1.47 192 12/5/2023
2.1.46 90 12/4/2023
2.1.45 91 12/4/2023
2.1.44 248 12/4/2023
2.1.43 98 12/4/2023
2.1.42 589 12/4/2023
2.1.41 77 12/4/2023
2.1.40 794 11/27/2023
2.1.39 318 11/26/2023
2.1.38 126 11/26/2023
2.1.37 351 11/23/2023
2.1.36 429 11/23/2023
2.1.35 422 11/23/2023
2.1.34 89 11/23/2023
2.1.33 206 11/23/2023
2.1.32 80 11/23/2023
2.1.31 702 11/20/2023
2.1.30 602 11/20/2023
2.1.29 480 11/19/2023
2.1.28 143 11/19/2023
2.1.27 305 11/19/2023
2.1.26 283 11/19/2023
2.1.25 282 11/19/2023
2.1.24 83 11/19/2023
2.1.23 147 11/18/2023
2.1.22 613 11/18/2023
2.1.21 231 11/18/2023
2.1.20 323 11/18/2023
2.1.19 90 11/18/2023
2.1.18 176 11/18/2023
2.1.17 90 11/18/2023
2.1.16 350 11/17/2023
2.1.15 297 11/17/2023
2.1.14 88 11/17/2023
2.1.13 292 11/17/2023
2.1.12 184 11/17/2023
2.1.11 284 11/17/2023
2.1.10 82 11/17/2023
2.1.9 280 11/17/2023
2.1.8 86 11/17/2023
2.1.7 92 11/17/2023
2.1.6 216 11/17/2023
2.1.5 193 11/16/2023
2.0.101 1,249 11/15/2023
2.0.100 75 11/15/2023
2.0.99 81 11/15/2023
2.0.4 87 11/16/2023
2.0.3 89 11/16/2023
2.0.2 87 11/16/2023
2.0.1 85 11/16/2023
1.0.98 396 11/14/2023
1.0.97 527 11/13/2023
1.0.96 79 11/13/2023
1.0.95 421 11/10/2023
1.0.94 81 11/10/2023
1.0.93 562 11/9/2023
1.0.92 84 11/9/2023
1.0.91 652 11/7/2023
1.0.90 78 11/7/2023
1.0.89 345 11/6/2023
1.0.88 83 11/6/2023
1.0.87 438 11/3/2023
1.0.86 94 11/3/2023
1.0.85 567 11/2/2023
1.0.84 83 11/2/2023
1.0.83 434 11/1/2023
1.0.82 976 10/26/2023
1.0.81 867 10/19/2023
1.0.80 96 10/19/2023
1.0.79 528 10/18/2023
1.0.78 104 10/18/2023
1.0.77 482 10/17/2023
1.0.76 98 10/17/2023
1.0.75 448 10/16/2023
1.0.74 99 10/16/2023
1.0.73 488 10/13/2023
1.0.72 240 10/12/2023
1.0.71 1,220 9/20/2023
1.0.70 414 9/19/2023
1.0.69 442 9/18/2023
1.0.68 96 9/18/2023
1.0.67 605 9/14/2023
1.0.66 1,051 8/31/2023
1.0.65 108 8/31/2023
1.0.64 538 8/30/2023
1.0.63 111 8/30/2023
1.0.62 110 8/30/2023
1.0.61 614 8/28/2023
1.0.60 502 8/25/2023
1.0.59 106 8/25/2023
1.0.58 341 8/24/2023
1.0.57 974 8/21/2023
1.0.56 540 8/18/2023
1.0.55 514 8/17/2023
1.0.54 115 8/17/2023
1.0.53 1,382 8/10/2023
1.0.52 414 8/9/2023
1.0.51 504 8/8/2023
1.0.50 474 8/7/2023
1.0.49 132 8/7/2023
1.0.48 1,736 7/13/2023
1.0.47 659 7/11/2023
1.0.46 554 7/10/2023
1.0.45 523 7/7/2023
1.0.44 127 7/7/2023
1.0.43 1,501 6/30/2023
1.0.42 790 6/29/2023
1.0.41 455 6/28/2023
1.0.40 1,146 6/26/2023
1.0.39 544 6/23/2023
1.0.38 793 6/21/2023
1.0.37 1,051 6/15/2023
1.0.36 343 6/14/2023
1.0.35 1,324 6/9/2023
1.0.34 647 6/8/2023
1.0.33 1,244 6/7/2023
1.0.32 124 6/7/2023
1.0.31 953 6/6/2023
1.0.30 900 6/5/2023
1.0.29 1,102 6/2/2023
1.0.28 114 6/2/2023
1.0.27 1,019 6/1/2023
1.0.26 482 5/31/2023
1.0.25 370 5/31/2023
1.0.24 116 5/31/2023
1.0.23 1,213 5/30/2023
1.0.22 1,259 5/26/2023
1.0.21 538 5/25/2023
1.0.20 112 5/25/2023
1.0.19 669 5/24/2023
1.0.18 114 5/24/2023
1.0.17 342 5/23/2023
1.0.13 1,172 5/22/2023
1.0.12 959 5/18/2023
1.0.11 459 5/17/2023
1.0.10 1,301 5/1/2023
1.0.9 832 4/25/2023
1.0.8 393 4/24/2023
1.0.7 856 4/21/2023
1.0.6 1,650 4/13/2023
1.0.5 487 4/12/2023
1.0.4 823 4/8/2023
1.0.3 151 4/8/2023
1.0.2 482 4/8/2023
1.0.1 148 4/8/2023