Microsoft.Extensions.Http (10.0.11)

Published 2026-09-09 02:36:35 +03:30 by kayer

Installation

dotnet nuget add source --name kayer --username your_username --password your_token 
dotnet add package --source kayer --version 10.0.11 Microsoft.Extensions.Http

About this package

The HttpClient factory is a pattern for configuring and retrieving named HttpClients in a composable way. The HttpClient factory provides extensibility to plug in DelegatingHandlers that address cross-cutting concerns such as service location, load balancing, and reliability. The default HttpClient factory provides built-in diagnostics and logging and manages the lifetimes of connections in a performant way.

Commonly Used Types: System.Net.Http.IHttpClientFactory

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.

Dependencies

ID Version Target Framework
Microsoft.Extensions.Configuration.Abstractions 10.0.11 .NETFramework4.6.2
Microsoft.Extensions.DependencyInjection.Abstractions 10.0.11 .NETFramework4.6.2
Microsoft.Extensions.Logging.Abstractions 10.0.11 .NETFramework4.6.2
Microsoft.Extensions.Logging 10.0.11 .NETFramework4.6.2
Microsoft.Extensions.Options 10.0.11 .NETFramework4.6.2
Microsoft.Extensions.Configuration.Abstractions 10.0.11 .NETStandard2.0
Microsoft.Extensions.DependencyInjection.Abstractions 10.0.11 .NETStandard2.0
Microsoft.Extensions.Logging.Abstractions 10.0.11 .NETStandard2.0
Microsoft.Extensions.Logging 10.0.11 .NETStandard2.0
Microsoft.Extensions.Options 10.0.11 .NETStandard2.0
Microsoft.Extensions.Configuration.Abstractions 10.0.11 net10.0
Microsoft.Extensions.DependencyInjection.Abstractions 10.0.11 net10.0
Microsoft.Extensions.Diagnostics 10.0.11 net10.0
Microsoft.Extensions.Logging.Abstractions 10.0.11 net10.0
Microsoft.Extensions.Logging 10.0.11 net10.0
Microsoft.Extensions.Options 10.0.11 net10.0
Microsoft.Extensions.Configuration.Abstractions 10.0.11 net8.0
Microsoft.Extensions.DependencyInjection.Abstractions 10.0.11 net8.0
Microsoft.Extensions.Diagnostics 10.0.11 net8.0
Microsoft.Extensions.Logging.Abstractions 10.0.11 net8.0
Microsoft.Extensions.Logging 10.0.11 net8.0
Microsoft.Extensions.Options 10.0.11 net8.0
Microsoft.Extensions.Configuration.Abstractions 10.0.11 net9.0
Microsoft.Extensions.DependencyInjection.Abstractions 10.0.11 net9.0
Microsoft.Extensions.Diagnostics 10.0.11 net9.0
Microsoft.Extensions.Logging.Abstractions 10.0.11 net9.0
Microsoft.Extensions.Logging 10.0.11 net9.0
Microsoft.Extensions.Options 10.0.11 net9.0
Details
NuGet
2026-09-09 02:36:35 +03:30
1
Microsoft
314 KiB
Assets (2)
Versions (1) View all
10.0.11 2026-09-09