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.
72
AspNetCore.HealthChecks.Uris
HealthChecks.Uris is a simple health check package for Uri groups.
70
AspNetCore.HealthChecks.Uris
HealthChecks.Uris is a simple health check package for Uri groups.
65
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
65
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/67acc3d331454956fc06d6de2218a625e3e596f8
65
AspNetCore.HealthChecks.Uris
HealthChecks.Uris is a simple health check package for Uri groups.
64
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/68bb6fb08f8f85bb3cf08953a0d2f4a254eaccff
64
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
63
AspNetCore.HealthChecks.Uris
HealthChecks.Uris is a simple health check package for Uri groups.
62
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/25bd01f17d5f01fc78bea5eb5308b2c0d79e2889
61
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
61
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
61
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/febee99db845fd8766a13bdb391a07c3ee90b4ba
61
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.
61
IdentityServer4
OpenID Connect and OAuth 2.0 Framework for ASP.NET Core
60

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-rc.2.25502.107 3 10/15/2025
10.0.0-rc.1.25451.107 10 09/11/2025
10.0.0-preview.7.25380.108 11 08/14/2025
10.0.0-preview.6.25358.103 12 07/17/2025
10.0.0-preview.5.25277.114 19 06/14/2025
10.0.0-preview.4.25258.110 21 05/13/2025
10.0.0-preview.3.25171.5 27 04/12/2025
10.0.0-preview.2.25163.2 25 03/23/2025
10.0.0-preview.1.25080.5 27 02/25/2025
9.0.10 3 10/15/2025
9.0.9 5 09/11/2025
9.0.8 9 08/07/2025
9.0.7 13 07/13/2025
9.0.6 15 06/12/2025
9.0.5 20 05/15/2025
9.0.4 28 04/11/2025
9.0.3 28 03/12/2025
9.0.2 29 02/14/2025
9.0.1 34 01/17/2025
9.0.0 44 11/13/2024
9.0.0-rc.2.24473.5 35 10/16/2024
9.0.0-rc.1.24431.7 34 09/11/2024
9.0.0-preview.7.24405.7 39 08/15/2024
9.0.0-preview.6.24327.7 45 07/11/2024
9.0.0-preview.5.24306.7 43 06/12/2024
9.0.0-preview.4.24266.19 40 05/23/2024
9.0.0-preview.3.24172.9 41 04/20/2024
9.0.0-preview.2.24128.5 45 03/19/2024
9.0.0-preview.1.24080.9 52 03/05/2024
8.0.1 42 10/17/2024
8.0.0 59 11/15/2023
8.0.0-rc.2.23479.6 45 10/19/2023
8.0.0-rc.1.23419.4 50 09/13/2023
8.0.0-preview.7.23375.6 43 08/24/2023
8.0.0-preview.6.23329.7 54 07/23/2023
8.0.0-preview.5.23280.8 43 07/05/2023
8.0.0-preview.4.23259.5 46 05/20/2023
8.0.0-preview.3.23174.8 42 05/13/2023
8.0.0-preview.2.23128.3 44 07/07/2023
8.0.0-preview.1.23110.8 49 02/25/2023
7.0.0 61 12/07/2022
7.0.0-rc.2.22472.3 47 07/03/2023
7.0.0-rc.1.22426.10 52 07/05/2023
7.0.0-preview.7.22375.6 49 11/05/2022
7.0.0-preview.6.22324.4 50 07/08/2023
7.0.0-preview.5.22301.12 46 05/06/2023
7.0.0-preview.4.22229.4 48 09/24/2022
7.0.0-preview.3.22175.4 43 06/29/2023
7.0.0-preview.2.22152.2 51 07/05/2023
7.0.0-preview.1.22076.8 57 09/26/2022
6.0.2-mauipre.1.22102.15 49 10/22/2022
6.0.2-mauipre.1.22054.8 50 11/18/2022
6.0.1 35 11/18/2024
6.0.0 56 07/28/2022
6.0.0-rc.2.21480.5 51 05/27/2023
6.0.0-rc.1.21451.13 45 07/04/2023
6.0.0-preview.7.21377.19 54 10/02/2022
6.0.0-preview.6.21352.12 41 07/05/2023
6.0.0-preview.5.21301.5 51 05/04/2023
6.0.0-preview.4.21253.7 48 04/25/2023
6.0.0-preview.3.21201.4 47 11/15/2022
6.0.0-preview.2.21154.6 52 11/16/2022
6.0.0-preview.1.21102.12 43 05/03/2023
5.0.0 54 07/03/2022
5.0.0-rc.2.20475.5 44 05/07/2023
5.0.0-rc.1.20451.14 43 05/12/2023
5.0.0-preview.8.20407.11 43 07/18/2023
5.0.0-preview.7.20364.11 53 07/03/2023
5.0.0-preview.6.20305.6 41 07/03/2023
5.0.0-preview.5.20278.1 49 02/20/2023
5.0.0-preview.4.20251.6 48 05/23/2023
5.0.0-preview.3.20215.2 45 05/19/2023
5.0.0-preview.2.20160.3 55 10/11/2022
5.0.0-preview.1.20120.4 54 01/18/2023
3.1.32 51 05/02/2023
3.1.31 52 01/17/2023
3.1.30 44 02/25/2023
3.1.29 54 12/19/2022
3.1.28 59 09/30/2022
3.1.27 56 10/11/2022
3.1.26 54 05/12/2023
3.1.25 48 10/03/2022
3.1.24 57 11/16/2022
3.1.23 55 10/03/2022
3.1.22 45 09/29/2022
3.1.21 51 10/08/2022
3.1.20 49 11/30/2022
3.1.19 48 09/29/2022
3.1.18 44 09/23/2022
3.1.17 52 09/26/2022
3.1.16 59 09/27/2022
3.1.15 50 10/08/2022
3.1.14 50 12/21/2022
3.1.13 47 05/16/2023
3.1.12 47 09/26/2022
3.1.11 48 10/07/2022
3.1.10 54 09/28/2022
3.1.9 51 09/25/2022
3.1.8 60 09/23/2022
3.1.7 63 11/19/2022
3.1.6 54 11/06/2022
3.1.5 61 11/30/2022
3.1.4 52 04/18/2023
3.1.3 62 09/23/2022
3.1.2 47 09/28/2022
3.1.1 62 09/22/2022
3.1.0 53 11/05/2022
3.1.0-preview3.19553.2 47 10/23/2022
3.1.0-preview2.19525.4 49 12/04/2022
3.1.0-preview1.19506.1 43 05/10/2023
3.0.3 55 10/29/2022
3.0.2 62 09/22/2022
3.0.1 55 11/19/2022
3.0.0 58 09/29/2022
3.0.0-rc1.19456.10 39 07/13/2023
3.0.0-preview9.19423.4 43 07/08/2023
3.0.0-preview8.19405.4 47 05/03/2023
3.0.0-preview7.19362.4 45 07/05/2023
3.0.0-preview6.19304.6 47 11/08/2022
3.0.0-preview5.19227.9 49 11/28/2022
3.0.0-preview4.19216.2 42 07/08/2023
3.0.0-preview3.19153.1 51 07/04/2023
3.0.0-preview.19074.2 41 07/03/2023
3.0.0-preview.18572.1 46 03/18/2023
2.2.0 62 09/23/2022
2.2.0-preview3-35497 53 10/10/2022
2.2.0-preview2-35157 47 05/24/2023
2.2.0-preview1-35029 44 10/26/2022
2.1.1 54 06/07/2022
2.1.0 57 09/30/2022
2.1.0-rc1-final 52 05/20/2023
2.1.0-preview2-final 49 09/23/2022
2.1.0-preview1-final 51 11/24/2022