Hymma.HttpClientFactory 1.0.7

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Hymma.HttpClientFactory --version 1.0.7
                    
NuGet\Install-Package Hymma.HttpClientFactory -Version 1.0.7
                    
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="Hymma.HttpClientFactory" Version="1.0.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hymma.HttpClientFactory" Version="1.0.7" />
                    
Directory.Packages.props
<PackageReference Include="Hymma.HttpClientFactory" />
                    
Project file
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 Hymma.HttpClientFactory --version 1.0.7
                    
#r "nuget: Hymma.HttpClientFactory, 1.0.7"
                    
#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 Hymma.HttpClientFactory@1.0.7
                    
#: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=Hymma.HttpClientFactory&version=1.0.7
                    
Install as a Cake Addin
#tool nuget:?package=Hymma.HttpClientFactory&version=1.0.7
                    
Install as a Cake Tool

HttpClientFactory For netcore And framework

NUGET Install-Package HttpClientFactory

supported netcore2.0 and framework4.5+

Why need HttpClientFactory?

As you know, HttpClient has a trap for using!

  1. if not Singleton, each instance of HttpClient will open a new socket connection and on high traffic sites you can exhaust the available pool and receive a System.Net.Sockets.SocketException
  2. if Singleton,HttpClient doesn't respect DNS changes!

So how to use HttpClient correctly?

//useage 1: same Host use same HttpClient
PerHostHttpClientFactory perHostHttpClientFactory = new PerHostHttpClientFactory();// can be static
//or you can change default timeout for perFactory
PerHostHttpClientFactory perHostHttpClientFactory = new PerHostHttpClientFactory(TimeSpan.FromSeconds(10));
HttpClient client = perHostHttpClientFactory.GetHttpClient("http://www.baidu.com");

//useage 2: per url use per HttpClient
PerUrlHttpClientFactory perUrlHttpClientFactory = new PerUrlHttpClientFactory();
//or you can change default timeout for perFactory
PerUrlHttpClientFactory perUrlHttpClientFactory = new PerUrlHttpClientFactory(TimeSpan.FromSeconds(10));
HttpClient client = perUrlHttpClientFactory.GetHttpClient("http://www.baidu.com");

//useage 3: per proxy use per HttpClient
PerHostHttpClientFactory perHostHttpClientFactory = new PerHostHttpClientFactory();
//or you can change default timeout for perFactory
PerHostHttpClientFactory perHostHttpClientFactory = new PerHostHttpClientFactory(TimeSpan.FromSeconds(10));
HttpClient client = perUrlHttpClientFactory.GetProxiedHttpClient("http://127.0.0.1:8080");

Easy to implement

	public class XXXHttpClientFactory : HttpClientFactoryBase
    {
        protected override string GetCacheKey(string key)
        {
            return key;
        }
				
				
		protected override HttpClient CreateHttpClient(HttpMessageHandler handler)
        {
            return new HttpClient(handler)
            {
                Timeout = TimeSpan.FromSeconds(20),
            };
        }

        protected override HttpMessageHandler CreateMessageHandler()
        {
            var handler = new HttpClientHandler();
            handler.Proxy = new WebProxy("xxx");
            return handler;
        }
    }

Remark

  1. Default Timeout is TimeSpan.FromSeconds(100)
  2. Default ConnectionLeaseExpired is TimeSpan.FromMinutes(1)
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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.  net9.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.5

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Hymma.HttpClientFactory:

Package Downloads
Hymma.Lm.EndUser

End-user SDK for license-management.com platform. Provides license validation, trial management, and activation handling for Windows desktop applications.

LicenseManagement.EndUser

End-user SDK for license-management.com platform. Provides license validation, trial management, and activation handling for Windows desktop applications.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.8 443 12/15/2025
1.0.7 313 11/28/2025

Strong-name signed version with configurable timeouts