Soenneker.Utils.HttpClientCache
4.0.1846
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Utils.HttpClientCache --version 4.0.1846
NuGet\Install-Package Soenneker.Utils.HttpClientCache -Version 4.0.1846
<PackageReference Include="Soenneker.Utils.HttpClientCache" Version="4.0.1846" />
<PackageVersion Include="Soenneker.Utils.HttpClientCache" Version="4.0.1846" />
<PackageReference Include="Soenneker.Utils.HttpClientCache" />
paket add Soenneker.Utils.HttpClientCache --version 4.0.1846
#r "nuget: Soenneker.Utils.HttpClientCache, 4.0.1846"
#:package Soenneker.Utils.HttpClientCache@4.0.1846
#addin nuget:?package=Soenneker.Utils.HttpClientCache&version=4.0.1846
#tool nuget:?package=Soenneker.Utils.HttpClientCache&version=4.0.1846
Soenneker.Utils.HttpClientCache
Providing thread-safe singleton HttpClients
Why?
'Long-lived' HttpClient static/singleton instances is the recommended use pattern in .NET. Avoid the unnecessary overhead of IHttpClientFactory, and definitely avoid creating a new HttpClient instance per request.
HttpClientCache provides a thread-safe singleton HttpClient instance per key via dependency injection. HttpClients are created lazily, and disposed on application shutdown (or manually if you want).
See Guidelines for using HttpClient
Installation
dotnet add package Soenneker.Utils.HttpClientCache
Usage
- Register
IHttpClientCachewithin DI (Program.cs).
public static async Task Main(string[] args)
{
...
builder.Services.AddHttpClientCache();
}
- Inject
IHttpClientCachevia constructor, and retrieve a freshHttpClient.
Example:
public class TestClass
{
IHttpClientCache _httpClientCache;
public TestClass(IHttpClientCache httpClientCache)
{
_httpClientCache = httpClientCache;
}
public async ValueTask<string> GetGoogleSource()
{
HttpClient httpClient = await _httpClientCache.Get(nameof(TestClass));
var response = await httpClient.GetAsync("https://www.google.com");
response.EnsureSuccessStatusCode();
var responseString = await response.Content.ReadAsStringAsync();
return responseString;
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.3)
- Soenneker.Dictionaries.Singletons (>= 4.0.11)
- Soenneker.Dtos.HttpClientOptions (>= 4.0.13)
- Soenneker.Utils.Runtime (>= 4.0.929)
NuGet packages (42)
Showing the top 5 NuGet packages that depend on Soenneker.Utils.HttpClientCache:
| Package | Downloads |
|---|---|
|
Soenneker.Cosmos.Client
A utility library for Azure Cosmos client accessibility |
|
|
Soenneker.Blob.Container
A utility library for Azure Blob storage container operations |
|
|
Soenneker.Validators.Email.Disposable.Online
A validation module checking for disposable email addresses via online sources |
|
|
Soenneker.Queue.Client
A utility library for Azure Queue (Storage) client accessibility |
|
|
Soenneker.Blob.Service
A utility library for Azure Blob storage service client operations |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.1848 | 213 | 2/12/2026 |
| 4.0.1847 | 1,155 | 2/12/2026 |
| 4.0.1846 | 2,652 | 2/11/2026 |
| 4.0.1845 | 3,226 | 2/10/2026 |
| 4.0.1844 | 980 | 2/10/2026 |
| 4.0.1843 | 4,563 | 2/10/2026 |
| 4.0.1842 | 6,994 | 2/6/2026 |
| 4.0.1841 | 1,509 | 2/6/2026 |
| 4.0.1840 | 5,081 | 2/4/2026 |
| 4.0.1839 | 9,745 | 1/28/2026 |
| 4.0.1838 | 7,629 | 1/23/2026 |
| 4.0.1837 | 2,795 | 1/22/2026 |
| 4.0.1836 | 3,391 | 1/22/2026 |
| 4.0.1835 | 90 | 1/22/2026 |
| 4.0.1834 | 2,170 | 1/22/2026 |
| 4.0.1833 | 3,415 | 1/21/2026 |
| 4.0.1832 | 3,537 | 1/21/2026 |
| 4.0.1831 | 2,823 | 1/20/2026 |
| 4.0.1830 | 7,782 | 1/18/2026 |
| 4.0.1829 | 2,081 | 1/18/2026 |