Microsoft.Extensions.Http 9.0.0-preview.5.24306.7

About

Microsoft.Extensions.Http package provides AddHttpClient extension methods for IServiceCollection, IHttpClientFactory interface and its default implementation. This provides the ability to set up named HttpClient configurations in a DI container and later retrieve them via an injected IHttpClientFactory instance.

Key Features

  • The package allows to fluently set up multiple HttpClient configurations for applications that use DI via AddHttpClient extension method.
  • HttpClientFactory caches HttpMessageHandler instances per configuration name, which allows to reuse resources between HttpClient instances to avoid port exhaustion.
  • HttpClientFactory manages lifetime of HttpMessageHandler instances and recycles connections to track DNS changes.

How to Use

Note that lifetime management of HttpClient instances created by HttpClientFactory is completely different from instances created manually. The strategies are to use either short-lived clients created by HttpClientFactory or long-lived clients with PooledConnectionLifetime set up. For more information, see the HttpClient lifetime management section in the conceptual docs and Guidelines for using HTTP clients.

Configuring HttpClient

builder.Services.AddHttpClient("foo"); // adding an HttpClient named "foo" with a default configuration

builder.Services.AddHttpClient("example", c => c.BaseAddress = new Uri("https://www.example.com")) // configuring HttpClient itself
    .AddHttpMessageHandler<MyAuthHandler>() // adding additional delegating handlers to form a message handler chain
    .ConfigurePrimaryHttpMessageHandler(b => new HttpClientHandler() { AllowAutoRedirect = false }) // configuring primary handler
    .SetHandlerLifetime(TimeSpan.FromMinutes(30)); // changing the handler recycling interval

Using the configured HttpClient

public class MyService
{
    public MyService(IHttpClientFactory httpClientFactory)
    {
        _httpClientFactory = httpClientFactory; // injecting the factory
    }

    private Task<string> GetExampleAsync(Uri uri, CancellationToken ct)
    {
        HttpClient exampleClient = _httpClientFactory.CreateClient("example"); // creating the client for the specified name
        return exampleClient.GetStringAsync(uri, ct); // using the client
    }
}

Main Types

The main types provided by this library are:

  • IHttpClientFactory
  • IHttpMessageHandlerFactory
  • HttpClientFactoryServiceCollectionExtensions

Additional Documentation

Feedback & Contributing

Microsoft.Extensions.Http is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.

Showing the top 20 packages that depend on Microsoft.Extensions.Http.

Packages Downloads
AspNetCore.HealthChecks.Uris
HealthChecks.Uris is a simple health check package for Uri groups.
57
Microsoft.AspNetCore.ApiAuthorization.IdentityServer
ASP.NET Core API Authorization package powered by Identity Server. This package was built from the source code at https://github.com/aspnet/AspNetCore/tree/cf2c5c9c6dca430b97aa96429b84d0da07eb77f1
53
Microsoft.AspNetCore.ApiAuthorization.IdentityServer
ASP.NET Core API Authorization package powered by Identity Server. This package was built from the source code at https://github.com/aspnet/AspNetCore/tree/509f6badec2f3162f0e50330cd9107e5624b379b
52
AspNetCore.HealthChecks.Uris
HealthChecks.Uris is a simple health check package for Uri groups.
51
AspNetCore.HealthChecks.Uris
HealthChecks.Uris is a simple health check package for Uri groups.
50
Microsoft.AspNetCore.ApiAuthorization.IdentityServer
ASP.NET Core API Authorization package powered by Identity Server. This package was built from the source code at https://github.com/aspnet/AspNetCore/tree/aee5e4080331553ea9dfb7fb388b6d72f715bf6a
50
Microsoft.AspNetCore.ApiAuthorization.IdentityServer
ASP.NET Core API Authorization package powered by Identity Server. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/f6897a5bb7ca767df8eb465bf15b193c878fffbf
50
Microsoft.AspNetCore.ApiAuthorization.IdentityServer
ASP.NET Core API Authorization package powered by Identity Server. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/55738ff96b832439076e25584cfe0eb3bace9b01
50
AspNetCore.HealthChecks.Uris
HealthChecks.Uris is a simple health check package for Uri groups.
49
Microsoft.AspNetCore.ApiAuthorization.IdentityServer
ASP.NET Core API Authorization package powered by Identity Server. This package was built from the source code at https://github.com/aspnet/AspNetCore/tree/0a2e366eaf4d29b24b9a98e5782a04bef573189e
48
AspNetCore.HealthChecks.Uris
HealthChecks.Uris is a simple health check package for Uri groups.
47
Microsoft.AspNetCore.ApiAuthorization.IdentityServer
ASP.NET Core API Authorization package powered by Identity Server. This package was built from the source code at https://github.com/aspnet/AspNetCore/tree/2e51a0b6eba74bdf02aee71944e973487937cb99
47
Microsoft.AspNetCore.All
Provides a default set of APIs for building an ASP.NET Core application, and also includes API for third-party integrations with ASP.NET Core. This package requires the ASP.NET Core runtime. This runtime is installed by the .NET Core SDK, or can be acquired separately using installers available at https://aka.ms/dotnet-download.
47
Microsoft.AspNetCore.ApiAuthorization.IdentityServer
ASP.NET Core API Authorization package powered by Identity Server. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/fb4b5a21ebd67b31fff4ddf5c039181da504c932
47
Microsoft.AspNetCore.ApiAuthorization.IdentityServer
ASP.NET Core API Authorization package powered by Identity Server. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/70048beee894074e9718206a0017d9b080ee66ff
47
Microsoft.AspNetCore.ApiAuthorization.IdentityServer
ASP.NET Core API Authorization package powered by Identity Server. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/0bc3c376f0cd14335e8b3afca69596acabeb1f80
46
Microsoft.AspNetCore.ApiAuthorization.IdentityServer
ASP.NET Core API Authorization package powered by Identity Server. This package was built from the source code at https://github.com/aspnet/AspNetCore/tree/80fec4e3edea3972e95885f5c0db6ee06072f917
46
Microsoft.AspNetCore.ApiAuthorization.IdentityServer
ASP.NET Core API Authorization package powered by Identity Server. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/e77cb01b5529c137130757859f09f892dbdd2436
46

https://go.microsoft.com/fwlink/?LinkID=799421

.NET Framework 4.6.2

.NET Standard 2.0

.NET 9.0

.NET 8.0

Version Downloads Last updated
10.0.0-preview.4.25258.110 0 05/12/2025
10.0.0-preview.3.25171.5 9 04/12/2025
10.0.0-preview.2.25163.2 10 03/23/2025
10.0.0-preview.1.25080.5 13 02/25/2025
9.0.4 7 04/11/2025
9.0.3 12 03/12/2025
9.0.2 10 02/14/2025
9.0.1 17 01/17/2025
9.0.0 25 11/13/2024
9.0.0-rc.2.24473.5 21 10/16/2024
9.0.0-rc.1.24431.7 17 09/11/2024
9.0.0-preview.7.24405.7 21 08/15/2024
9.0.0-preview.6.24327.7 29 07/11/2024
9.0.0-preview.5.24306.7 27 06/12/2024
9.0.0-preview.4.24266.19 25 05/23/2024
9.0.0-preview.3.24172.9 25 04/20/2024
9.0.0-preview.2.24128.5 31 03/19/2024
9.0.0-preview.1.24080.9 31 03/05/2024
8.0.1 25 10/17/2024
8.0.0 34 11/15/2023
8.0.0-rc.2.23479.6 30 10/19/2023
8.0.0-rc.1.23419.4 39 09/13/2023
8.0.0-preview.7.23375.6 29 08/24/2023
8.0.0-preview.6.23329.7 33 07/23/2023
8.0.0-preview.5.23280.8 28 07/05/2023
8.0.0-preview.4.23259.5 31 05/20/2023
8.0.0-preview.3.23174.8 28 05/13/2023
8.0.0-preview.2.23128.3 29 07/07/2023
8.0.0-preview.1.23110.8 31 02/25/2023
7.0.0 46 12/07/2022
7.0.0-rc.2.22472.3 30 07/03/2023
7.0.0-rc.1.22426.10 34 07/05/2023
7.0.0-preview.7.22375.6 33 11/05/2022
7.0.0-preview.6.22324.4 29 07/08/2023
7.0.0-preview.5.22301.12 32 05/06/2023
7.0.0-preview.4.22229.4 27 09/24/2022
7.0.0-preview.3.22175.4 27 06/29/2023
7.0.0-preview.2.22152.2 32 07/05/2023
7.0.0-preview.1.22076.8 38 09/26/2022
6.0.2-mauipre.1.22102.15 34 10/22/2022
6.0.2-mauipre.1.22054.8 34 11/18/2022
6.0.1 18 11/18/2024
6.0.0 45 07/28/2022
6.0.0-rc.2.21480.5 37 05/27/2023
6.0.0-rc.1.21451.13 30 07/04/2023
6.0.0-preview.7.21377.19 37 10/02/2022
6.0.0-preview.6.21352.12 26 07/05/2023
6.0.0-preview.5.21301.5 31 05/04/2023
6.0.0-preview.4.21253.7 34 04/25/2023
6.0.0-preview.3.21201.4 30 11/15/2022
6.0.0-preview.2.21154.6 36 11/16/2022
6.0.0-preview.1.21102.12 29 05/03/2023
5.0.0 36 07/03/2022
5.0.0-rc.2.20475.5 30 05/07/2023
5.0.0-rc.1.20451.14 32 05/12/2023
5.0.0-preview.8.20407.11 32 07/18/2023
5.0.0-preview.7.20364.11 35 07/03/2023
5.0.0-preview.6.20305.6 27 07/03/2023
5.0.0-preview.5.20278.1 36 02/20/2023
5.0.0-preview.4.20251.6 35 05/23/2023
5.0.0-preview.3.20215.2 29 05/19/2023
5.0.0-preview.2.20160.3 37 10/11/2022
5.0.0-preview.1.20120.4 39 01/18/2023
3.1.32 36 05/02/2023
3.1.31 38 01/17/2023
3.1.30 31 02/25/2023
3.1.29 39 12/19/2022
3.1.28 41 09/30/2022
3.1.27 39 10/11/2022
3.1.26 39 05/12/2023
3.1.25 35 10/03/2022
3.1.24 38 11/16/2022
3.1.23 39 10/03/2022
3.1.22 32 09/29/2022
3.1.21 38 10/08/2022
3.1.20 32 11/30/2022
3.1.19 33 09/29/2022
3.1.18 34 09/23/2022
3.1.17 37 09/26/2022
3.1.16 43 09/27/2022
3.1.15 34 10/08/2022
3.1.14 36 12/21/2022
3.1.13 31 05/16/2023
3.1.12 34 09/26/2022
3.1.11 29 10/07/2022
3.1.10 36 09/28/2022
3.1.9 36 09/25/2022
3.1.8 40 09/23/2022
3.1.7 42 11/19/2022
3.1.6 36 11/06/2022
3.1.5 42 11/30/2022
3.1.4 37 04/18/2023
3.1.3 46 09/23/2022
3.1.2 33 09/28/2022
3.1.1 38 09/22/2022
3.1.0 38 11/05/2022
3.1.0-preview3.19553.2 31 10/23/2022
3.1.0-preview2.19525.4 37 12/04/2022
3.1.0-preview1.19506.1 29 05/10/2023
3.0.3 37 10/29/2022
3.0.2 42 09/22/2022
3.0.1 38 11/19/2022
3.0.0 46 09/29/2022
3.0.0-rc1.19456.10 23 07/13/2023
3.0.0-preview9.19423.4 26 07/08/2023
3.0.0-preview8.19405.4 33 05/03/2023
3.0.0-preview7.19362.4 30 07/05/2023
3.0.0-preview6.19304.6 33 11/08/2022
3.0.0-preview5.19227.9 33 11/28/2022
3.0.0-preview4.19216.2 26 07/08/2023
3.0.0-preview3.19153.1 32 07/04/2023
3.0.0-preview.19074.2 26 07/03/2023
3.0.0-preview.18572.1 28 03/18/2023
2.2.0 45 09/23/2022
2.2.0-preview3-35497 34 10/10/2022
2.2.0-preview2-35157 33 05/24/2023
2.2.0-preview1-35029 30 10/26/2022
2.1.1 35 06/07/2022
2.1.0 41 09/30/2022
2.1.0-rc1-final 38 05/20/2023
2.1.0-preview2-final 34 09/23/2022
2.1.0-preview1-final 34 11/24/2022