Soenneker.Utils.SingletonDictionary
3.0.1046
Prefix Reserved
The owner has unlisted this package.
This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Soenneker.Utils.SingletonDictionary --version 3.0.1046
NuGet\Install-Package Soenneker.Utils.SingletonDictionary -Version 3.0.1046
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="3.0.1046" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Utils.SingletonDictionary" Version="3.0.1046" />
<PackageReference Include="Soenneker.Utils.SingletonDictionary" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Utils.SingletonDictionary --version 3.0.1046
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Soenneker.Utils.SingletonDictionary, 3.0.1046"
#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.
#:package Soenneker.Utils.SingletonDictionary@3.0.1046
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Utils.SingletonDictionary&version=3.0.1046
#tool nuget:?package=Soenneker.Utils.SingletonDictionary&version=3.0.1046
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- Nito.AsyncEx (>= 5.1.2)
- Soenneker.Extensions.Enumerable (>= 3.0.523)
- Soenneker.Extensions.ValueTask (>= 3.0.86)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|
Loading failed