Soenneker.Utils.SingletonDictionary 2.1.202

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

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

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

NuGet packages (5)

Showing the top 5 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.Queue.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 Queue (Storage) client accessibility

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.202 265 2/22/2024
2.1.201 307 2/22/2024
2.1.200 153 2/21/2024
2.1.199 448 2/21/2024
2.1.198 87 2/21/2024
2.1.197 300 2/21/2024
2.1.196 44 2/21/2024
2.1.195 465 2/21/2024
2.1.194 171 2/21/2024
2.1.193 41 2/21/2024
2.1.192 41 2/21/2024
2.1.191 186 2/21/2024
2.1.190 40 2/21/2024
2.1.189 1,020 2/20/2024
2.1.188 308 2/20/2024
2.1.187 263 2/20/2024
2.1.186 348 2/20/2024
2.1.185 1,078 2/19/2024
2.1.184 1,090 2/17/2024
2.1.183 510 2/16/2024
2.1.182 428 2/16/2024
2.1.181 762 2/16/2024
2.1.180 39 2/16/2024
2.1.179 333 2/16/2024
2.1.178 42 2/16/2024
2.1.177 49 2/16/2024
2.1.176 262 2/16/2024
2.1.175 52 2/16/2024
2.1.174 2,014 2/13/2024
2.1.173 787 2/13/2024
2.1.172 633 2/13/2024
2.1.171 288 2/13/2024
2.1.170 306 2/13/2024
2.1.169 1,174 2/12/2024
2.1.168 278 2/11/2024
2.1.167 893 2/11/2024
2.1.166 497 2/11/2024
2.1.165 1,681 2/10/2024
2.1.164 326 2/9/2024
2.1.163 52 2/9/2024
2.1.162 940 2/9/2024
2.1.161 921 2/9/2024
2.1.160 220 2/8/2024
2.1.159 782 2/8/2024
2.1.158 400 2/8/2024
2.1.157 900 2/8/2024
2.1.156 55 2/8/2024
2.1.155 1,115 2/7/2024
2.1.154 258 2/7/2024
2.1.153 352 2/7/2024
2.1.152 742 2/7/2024
2.1.151 190 2/6/2024
2.1.150 64 2/6/2024
2.1.149 49 2/6/2024
2.1.148 1,709 2/5/2024
2.1.147 921 2/4/2024
2.1.146 1,225 2/2/2024
2.1.145 1,233 1/31/2024
2.1.144 1,355 1/29/2024
2.1.143 801 1/29/2024
2.1.142 203 1/29/2024
2.1.141 921 1/28/2024
2.1.140 250 1/28/2024
2.1.139 186 1/28/2024
2.1.138 259 1/28/2024
2.1.137 1,192 1/28/2024
2.1.136 617 1/28/2024
2.1.135 174 1/27/2024
2.1.134 531 1/27/2024
2.1.133 743 1/27/2024
2.1.132 719 1/27/2024
2.1.131 82 1/27/2024
2.1.130 422 1/27/2024
2.1.129 684 1/26/2024
2.1.128 125 1/26/2024
2.1.127 527 1/26/2024
2.1.126 705 1/26/2024
2.1.125 1,063 1/26/2024
2.1.124 561 1/25/2024
2.1.123 595 1/25/2024
2.1.122 291 1/25/2024
2.1.121 532 1/25/2024
2.1.120 281 1/25/2024
2.1.119 1,693 1/19/2024
2.1.118 1,447 1/15/2024
2.1.117 311 1/15/2024
2.1.116 824 1/15/2024
2.1.115 68 1/15/2024
2.1.114 373 1/15/2024
2.1.113 838 1/15/2024
2.1.112 1,642 1/14/2024
2.1.111 1,061 1/13/2024
2.1.110 1,171 1/12/2024
2.1.109 1,376 1/11/2024
2.1.108 1,743 1/7/2024
2.1.107 1,407 1/5/2024
2.1.106 310 1/5/2024
2.1.105 79 1/5/2024
2.1.104 74 1/5/2024
2.1.103 904 1/5/2024
2.1.102 88 1/5/2024
2.1.101 1,812 1/1/2024
2.1.100 1,472 12/28/2023
2.1.99 535 12/28/2023
2.1.98 335 12/28/2023
2.1.97 84 12/28/2023
2.1.96 82 12/28/2023
2.1.95 528 12/27/2023
2.1.94 74 12/27/2023
2.1.93 328 12/27/2023
2.1.92 68 12/27/2023
2.1.91 74 12/27/2023
2.1.90 1,545 12/25/2023
2.1.89 232 12/25/2023
2.1.88 467 12/25/2023
2.1.87 74 12/25/2023
2.1.86 409 12/25/2023
2.1.85 81 12/25/2023
2.1.84 370 12/25/2023
2.1.83 73 12/25/2023
2.1.82 1,090 12/24/2023
2.1.81 743 12/23/2023
2.1.80 533 12/23/2023
2.1.79 209 12/23/2023
2.1.78 365 12/23/2023
2.1.77 82 12/23/2023
2.1.76 70 12/23/2023
2.1.75 720 12/23/2023
2.1.74 69 12/23/2023
2.1.73 933 12/19/2023
2.1.72 141 12/19/2023
2.1.71 2,123 12/11/2023
2.1.70 489 12/10/2023
2.1.69 80 12/10/2023
2.1.68 338 12/10/2023
2.1.67 960 12/10/2023
2.1.66 235 12/9/2023
2.1.65 240 12/9/2023
2.1.64 183 12/9/2023
2.1.63 76 12/9/2023
2.1.62 183 12/9/2023
2.1.61 126 12/9/2023
2.1.60 75 12/9/2023
2.1.59 745 12/9/2023
2.1.58 75 12/9/2023
2.1.57 1,017 12/6/2023
2.1.56 226 12/6/2023
2.1.55 126 12/6/2023
2.1.54 186 12/6/2023
2.1.53 582 12/5/2023
2.1.52 233 12/5/2023
2.1.51 222 12/5/2023
2.1.50 226 12/5/2023
2.1.49 79 12/5/2023
2.1.48 228 12/5/2023
2.1.47 170 12/5/2023
2.1.46 81 12/4/2023
2.1.45 81 12/4/2023
2.1.44 240 12/4/2023
2.1.43 88 12/4/2023
2.1.42 562 12/4/2023
2.1.41 68 12/4/2023
2.1.40 767 11/27/2023
2.1.39 302 11/26/2023
2.1.38 117 11/26/2023
2.1.37 333 11/23/2023
2.1.36 403 11/23/2023
2.1.35 391 11/23/2023
2.1.34 79 11/23/2023
2.1.33 197 11/23/2023
2.1.32 72 11/23/2023
2.1.31 674 11/20/2023
2.1.30 568 11/20/2023
2.1.29 454 11/19/2023
2.1.28 134 11/19/2023
2.1.27 288 11/19/2023
2.1.26 251 11/19/2023
2.1.25 273 11/19/2023
2.1.24 76 11/19/2023
2.1.23 137 11/18/2023
2.1.22 593 11/18/2023
2.1.21 223 11/18/2023
2.1.20 314 11/18/2023
2.1.19 81 11/18/2023
2.1.18 168 11/18/2023
2.1.17 82 11/18/2023
2.1.16 340 11/17/2023
2.1.15 287 11/17/2023
2.1.14 79 11/17/2023
2.1.13 282 11/17/2023
2.1.12 175 11/17/2023
2.1.11 272 11/17/2023
2.1.10 72 11/17/2023
2.1.9 269 11/17/2023
2.1.8 76 11/17/2023
2.1.7 83 11/17/2023
2.1.6 206 11/17/2023
2.1.5 183 11/16/2023
2.0.101 1,240 11/15/2023
2.0.100 70 11/15/2023
2.0.99 75 11/15/2023
2.0.4 78 11/16/2023
2.0.3 79 11/16/2023
2.0.2 76 11/16/2023
2.0.1 76 11/16/2023
1.0.98 385 11/14/2023
1.0.97 515 11/13/2023
1.0.96 69 11/13/2023
1.0.95 412 11/10/2023
1.0.94 71 11/10/2023
1.0.93 553 11/9/2023
1.0.92 76 11/9/2023
1.0.91 642 11/7/2023
1.0.90 68 11/7/2023
1.0.89 334 11/6/2023
1.0.88 72 11/6/2023
1.0.87 427 11/3/2023
1.0.86 82 11/3/2023
1.0.85 555 11/2/2023
1.0.84 72 11/2/2023
1.0.83 423 11/1/2023
1.0.82 965 10/26/2023
1.0.81 858 10/19/2023
1.0.80 87 10/19/2023
1.0.79 519 10/18/2023
1.0.78 95 10/18/2023
1.0.77 473 10/17/2023
1.0.76 89 10/17/2023
1.0.75 440 10/16/2023
1.0.74 91 10/16/2023
1.0.73 479 10/13/2023
1.0.72 230 10/12/2023
1.0.71 1,209 9/20/2023
1.0.70 404 9/19/2023
1.0.69 432 9/18/2023
1.0.68 86 9/18/2023
1.0.67 596 9/14/2023
1.0.66 1,038 8/31/2023
1.0.65 95 8/31/2023
1.0.64 526 8/30/2023
1.0.63 99 8/30/2023
1.0.62 98 8/30/2023
1.0.61 602 8/28/2023
1.0.60 491 8/25/2023
1.0.59 94 8/25/2023
1.0.58 328 8/24/2023
1.0.57 961 8/21/2023
1.0.56 528 8/18/2023
1.0.55 502 8/17/2023
1.0.54 102 8/17/2023
1.0.53 1,369 8/10/2023
1.0.52 401 8/9/2023
1.0.51 492 8/8/2023
1.0.50 462 8/7/2023
1.0.49 120 8/7/2023
1.0.48 1,721 7/13/2023
1.0.47 646 7/11/2023
1.0.46 543 7/10/2023
1.0.45 512 7/7/2023
1.0.44 116 7/7/2023
1.0.43 1,489 6/30/2023
1.0.42 779 6/29/2023
1.0.41 445 6/28/2023
1.0.40 1,136 6/26/2023
1.0.39 533 6/23/2023
1.0.38 782 6/21/2023
1.0.37 1,039 6/15/2023
1.0.36 329 6/14/2023
1.0.35 1,313 6/9/2023
1.0.34 634 6/8/2023
1.0.33 1,232 6/7/2023
1.0.32 112 6/7/2023
1.0.31 941 6/6/2023
1.0.30 889 6/5/2023
1.0.29 1,091 6/2/2023
1.0.28 103 6/2/2023
1.0.27 1,006 6/1/2023
1.0.26 469 5/31/2023
1.0.25 358 5/31/2023
1.0.24 104 5/31/2023
1.0.23 1,202 5/30/2023
1.0.22 1,248 5/26/2023
1.0.21 527 5/25/2023
1.0.20 101 5/25/2023
1.0.19 657 5/24/2023
1.0.18 103 5/24/2023
1.0.17 331 5/23/2023
1.0.13 1,160 5/22/2023
1.0.12 947 5/18/2023
1.0.11 448 5/17/2023
1.0.10 1,290 5/1/2023
1.0.9 822 4/25/2023
1.0.8 384 4/24/2023
1.0.7 847 4/21/2023
1.0.6 1,641 4/13/2023
1.0.5 479 4/12/2023
1.0.4 814 4/8/2023
1.0.3 143 4/8/2023
1.0.2 474 4/8/2023
1.0.1 140 4/8/2023