HttpClientFactoryServiceCollectionExtensions.AddHttpClient Method

Definition

Overloads

AddHttpClient(IServiceCollection)

Adds the IHttpClientFactory and related services to the IServiceCollection.

AddHttpClient(IServiceCollection, String)

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a named HttpClient.

AddHttpClient(IServiceCollection, String, Action<IServiceProvider,HttpClient>)

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a named HttpClient.

AddHttpClient(IServiceCollection, String, Action<HttpClient>)

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a named HttpClient.

AddHttpClient<TClient,TImplementation>(IServiceCollection, String, Func<HttpClient,IServiceProvider,TImplementation>)

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient.

AddHttpClient<TClient,TImplementation>(IServiceCollection, String, Action<HttpClient>)

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient.

AddHttpClient<TClient,TImplementation>(IServiceCollection, String, Action<IServiceProvider,HttpClient>)

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient.

AddHttpClient<TClient,TImplementation>(IServiceCollection, String)

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient.

AddHttpClient<TClient,TImplementation>(IServiceCollection, Func<HttpClient,TImplementation>)

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient.

AddHttpClient<TClient,TImplementation>(IServiceCollection, Func<HttpClient,IServiceProvider,TImplementation>)

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient.

AddHttpClient<TClient,TImplementation>(IServiceCollection, Action<HttpClient>)

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient. The client name will be set to the type name of TClient.

AddHttpClient<TClient,TImplementation>(IServiceCollection)

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient. The client name will be set to the type name of TClient.

AddHttpClient<TClient,TImplementation>(IServiceCollection, String, Func<HttpClient,TImplementation>)

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient.

AddHttpClient<TClient,TImplementation>(IServiceCollection, Action<IServiceProvider,HttpClient>)

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient. The client name will be set to the type name of TClient.

AddHttpClient<TClient>(IServiceCollection, String, Action<HttpClient>)

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient.

AddHttpClient<TClient>(IServiceCollection, String, Action<IServiceProvider,HttpClient>)

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient.

AddHttpClient<TClient>(IServiceCollection, String)

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient.

AddHttpClient<TClient>(IServiceCollection, Action<HttpClient>)

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient. The client name will be set to the type name of TClient.

AddHttpClient<TClient>(IServiceCollection, Action<IServiceProvider,HttpClient>)

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient. The client name will be set to the type name of TClient.

AddHttpClient<TClient>(IServiceCollection)

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient. The client name will be set to the type name of TClient.

AddHttpClient(IServiceCollection)

Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs

Adds the IHttpClientFactory and related services to the IServiceCollection.

C#
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddHttpClient(this Microsoft.Extensions.DependencyInjection.IServiceCollection services);

Parameters

Returns

The IServiceCollection.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

AddHttpClient(IServiceCollection, String)

Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a named HttpClient.

C#
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder AddHttpClient(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string name);

Parameters

name
String

The logical name of the HttpClient to configure.

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

HttpClient instances that apply the provided configuration can be retrieved using CreateClient(String) and providing the matching name.

Use DefaultName as the name to configure the default client.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

AddHttpClient(IServiceCollection, String, Action<IServiceProvider,HttpClient>)

Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a named HttpClient.

C#
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder AddHttpClient(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string name, Action<IServiceProvider,System.Net.Http.HttpClient> configureClient);

Parameters

name
String

The logical name of the HttpClient to configure.

configureClient
Action<IServiceProvider,HttpClient>

A delegate that is used to configure an HttpClient.

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

HttpClient instances that apply the provided configuration can be retrieved using CreateClient(String) and providing the matching name.

Use DefaultName as the name to configure the default client.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

AddHttpClient(IServiceCollection, String, Action<HttpClient>)

Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a named HttpClient.

C#
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder AddHttpClient(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string name, Action<System.Net.Http.HttpClient> configureClient);

Parameters

name
String

The logical name of the HttpClient to configure.

configureClient
Action<HttpClient>

A delegate that is used to configure an HttpClient.

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

HttpClient instances that apply the provided configuration can be retrieved using CreateClient(String) and providing the matching name.

Use DefaultName as the name to configure the default client.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

AddHttpClient<TClient,TImplementation>(IServiceCollection, String, Func<HttpClient,IServiceProvider,TImplementation>)

Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient.

C#
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder AddHttpClient<TClient,TImplementation>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string name, Func<System.Net.Http.HttpClient,IServiceProvider,TImplementation> factory) where TClient : class where TImplementation : class, TClient;

Type Parameters

TClient

The type of the typed client. The type specified will be registered in the service collection as a transient service. See ITypedHttpClientFactory<TClient> for more details about authoring typed clients.

TImplementation

The implementation type of the typed client.

Parameters

name
String

The logical name of the HttpClient to configure.

factory
Func<HttpClient,IServiceProvider,TImplementation>

A delegate that is used to create an instance of TClient.

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

HttpClient instances that apply the provided configuration can be retrieved using CreateClient(String) and providing the matching name.

TClient instances constructed with the appropriate HttpClient can be retrieved from GetService(Type) (and related methods) by providing TClient as the service type.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

AddHttpClient<TClient,TImplementation>(IServiceCollection, String, Action<HttpClient>)

Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient.

C#
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder AddHttpClient<TClient,TImplementation>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string name, Action<System.Net.Http.HttpClient> configureClient) where TClient : class where TImplementation : class, TClient;

Type Parameters

TClient

The type of the typed client. The type specified will be registered in the service collection as a transient service. See ITypedHttpClientFactory<TClient> for more details about authoring typed clients.

TImplementation

The implementation type of the typed client. The type specified will be instantiated by the ITypedHttpClientFactory<TClient>.

Parameters

name
String

The logical name of the HttpClient to configure.

configureClient
Action<HttpClient>

A delegate that is used to configure an HttpClient.

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

HttpClient instances that apply the provided configuration can be retrieved using CreateClient(String) and providing the matching name.

TClient instances constructed with the appropriate HttpClient can be retrieved from GetService(Type) (and related methods) by providing TClient as the service type.

Use DefaultName as the name to configure the default client.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

AddHttpClient<TClient,TImplementation>(IServiceCollection, String, Action<IServiceProvider,HttpClient>)

Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient.

C#
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder AddHttpClient<TClient,TImplementation>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string name, Action<IServiceProvider,System.Net.Http.HttpClient> configureClient) where TClient : class where TImplementation : class, TClient;

Type Parameters

TClient

The type of the typed client. The type specified will be registered in the service collection as a transient service. See ITypedHttpClientFactory<TClient> for more details about authoring typed clients.

TImplementation

The implementation type of the typed client. The type specified will be instantiated by the ITypedHttpClientFactory<TClient>.

Parameters

name
String

The logical name of the HttpClient to configure.

configureClient
Action<IServiceProvider,HttpClient>

A delegate that is used to configure an HttpClient.

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

HttpClient instances that apply the provided configuration can be retrieved using CreateClient(String) and providing the matching name.

TClient instances constructed with the appropriate HttpClient can be retrieved from GetService(Type) (and related methods) by providing TClient as the service type.

Use DefaultName as the name to configure the default client.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

AddHttpClient<TClient,TImplementation>(IServiceCollection, String)

Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient.

C#
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder AddHttpClient<TClient,TImplementation>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string name) where TClient : class where TImplementation : class, TClient;

Type Parameters

TClient

The type of the typed client. The type specified will be registered in the service collection as a transient service. See ITypedHttpClientFactory<TClient> for more details about authoring typed clients.

TImplementation

The implementation type of the typed client. The type specified will be instantiated by the ITypedHttpClientFactory<TClient>.

Parameters

name
String

The logical name of the HttpClient to configure.

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

HttpClient instances that apply the provided configuration can be retrieved using CreateClient(String) and providing the matching name.

TClient instances constructed with the appropriate HttpClient can be retrieved from GetService(Type) (and related methods) by providing TClient as the service type.

Use DefaultName as the name to configure the default client.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

AddHttpClient<TClient,TImplementation>(IServiceCollection, Func<HttpClient,TImplementation>)

Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient.

C#
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder AddHttpClient<TClient,TImplementation>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Func<System.Net.Http.HttpClient,TImplementation> factory) where TClient : class where TImplementation : class, TClient;

Type Parameters

TClient

The type of the typed client. The type specified will be registered in the service collection as a transient service. See ITypedHttpClientFactory<TClient> for more details about authoring typed clients.

TImplementation

The implementation type of the typed client.

Parameters

factory
Func<HttpClient,TImplementation>

A delegate that is used to create an instance of TClient.

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

HttpClient instances that apply the provided configuration can be retrieved using CreateClient(String) and providing the matching name.

TClient instances constructed with the appropriate HttpClient can be retrieved from GetService(Type) (and related methods) by providing TClient as the service type.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

AddHttpClient<TClient,TImplementation>(IServiceCollection, Func<HttpClient,IServiceProvider,TImplementation>)

Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient.

C#
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder AddHttpClient<TClient,TImplementation>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Func<System.Net.Http.HttpClient,IServiceProvider,TImplementation> factory) where TClient : class where TImplementation : class, TClient;

Type Parameters

TClient

The type of the typed client. The type specified will be registered in the service collection as a transient service. See ITypedHttpClientFactory<TClient> for more details about authoring typed clients.

TImplementation

The implementation type of the typed client.

Parameters

factory
Func<HttpClient,IServiceProvider,TImplementation>

A delegate that is used to create an instance of TClient.

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

HttpClient instances that apply the provided configuration can be retrieved using CreateClient(String) and providing the matching name.

TClient instances constructed with the appropriate HttpClient can be retrieved from GetService(Type) (and related methods) by providing TClient as the service type.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

AddHttpClient<TClient,TImplementation>(IServiceCollection, Action<HttpClient>)

Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient. The client name will be set to the type name of TClient.

C#
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder AddHttpClient<TClient,TImplementation>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Action<System.Net.Http.HttpClient> configureClient) where TClient : class where TImplementation : class, TClient;

Type Parameters

TClient

The type of the typed client. The type specified will be registered in the service collection as a transient service. See ITypedHttpClientFactory<TClient> for more details about authoring typed clients.

TImplementation

The implementation type of the typed client. The type specified will be instantiated by the ITypedHttpClientFactory<TClient>.

Parameters

configureClient
Action<HttpClient>

A delegate that is used to configure an HttpClient.

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

HttpClient instances that apply the provided configuration can be retrieved using CreateClient(String) and providing the matching name.

TClient instances constructed with the appropriate HttpClient can be retrieved from GetService(Type) (and related methods) by providing TClient as the service type.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

AddHttpClient<TClient,TImplementation>(IServiceCollection)

Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient. The client name will be set to the type name of TClient.

C#
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder AddHttpClient<TClient,TImplementation>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) where TClient : class where TImplementation : class, TClient;

Type Parameters

TClient

The type of the typed client. The type specified will be registered in the service collection as a transient service. See ITypedHttpClientFactory<TClient> for more details about authoring typed clients.

TImplementation

The implementation type of the typed client. The type specified will be instantiated by the ITypedHttpClientFactory<TClient>.

Parameters

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

HttpClient instances that apply the provided configuration can be retrieved using CreateClient(String) and providing the matching name.

TClient instances constructed with the appropriate HttpClient can be retrieved from GetService(Type) (and related methods) by providing TClient as the service type.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

AddHttpClient<TClient,TImplementation>(IServiceCollection, String, Func<HttpClient,TImplementation>)

Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient.

C#
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder AddHttpClient<TClient,TImplementation>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string name, Func<System.Net.Http.HttpClient,TImplementation> factory) where TClient : class where TImplementation : class, TClient;

Type Parameters

TClient

The type of the typed client. The type specified will be registered in the service collection as a transient service. See ITypedHttpClientFactory<TClient> for more details about authoring typed clients.

TImplementation

The implementation type of the typed client.

Parameters

name
String

The logical name of the HttpClient to configure.

factory
Func<HttpClient,TImplementation>

A delegate that is used to create an instance of TClient.

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

HttpClient instances that apply the provided configuration can be retrieved using CreateClient(String) and providing the matching name.

TClient instances constructed with the appropriate HttpClient can be retrieved from GetService(Type) (and related methods) by providing TClient as the service type.

TImplementation

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

AddHttpClient<TClient,TImplementation>(IServiceCollection, Action<IServiceProvider,HttpClient>)

Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient. The client name will be set to the type name of TClient.

C#
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder AddHttpClient<TClient,TImplementation>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Action<IServiceProvider,System.Net.Http.HttpClient> configureClient) where TClient : class where TImplementation : class, TClient;

Type Parameters

TClient

The type of the typed client. The type specified will be registered in the service collection as a transient service. See ITypedHttpClientFactory<TClient> for more details about authoring typed clients.

TImplementation

The implementation type of the typed client. The type specified will be instantiated by the ITypedHttpClientFactory<TClient>.

Parameters

configureClient
Action<IServiceProvider,HttpClient>

A delegate that is used to configure an HttpClient.

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

HttpClient instances that apply the provided configuration can be retrieved using CreateClient(String) and providing the matching name.

TClient instances constructed with the appropriate HttpClient can be retrieved from GetService(Type) (and related methods) by providing TClient as the service type.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

AddHttpClient<TClient>(IServiceCollection, String, Action<HttpClient>)

Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient.

C#
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder AddHttpClient<TClient>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string name, Action<System.Net.Http.HttpClient> configureClient) where TClient : class;

Type Parameters

TClient

The type of the typed client. The type specified will be registered in the service collection as a transient service. See ITypedHttpClientFactory<TClient> for more details about authoring typed clients.

Parameters

name
String

The logical name of the HttpClient to configure.

configureClient
Action<HttpClient>

A delegate that is used to configure an HttpClient.

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

HttpClient instances that apply the provided configuration can be retrieved using CreateClient(String) and providing the matching name.

TClient instances constructed with the appropriate HttpClient can be retrieved from GetService(Type) (and related methods) by providing TClient as the service type.

Use DefaultName as the name to configure the default client.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

AddHttpClient<TClient>(IServiceCollection, String, Action<IServiceProvider,HttpClient>)

Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient.

C#
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder AddHttpClient<TClient>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string name, Action<IServiceProvider,System.Net.Http.HttpClient> configureClient) where TClient : class;

Type Parameters

TClient

The type of the typed client. The type specified will be registered in the service collection as a transient service. See ITypedHttpClientFactory<TClient> for more details about authoring typed clients.

Parameters

name
String

The logical name of the HttpClient to configure.

configureClient
Action<IServiceProvider,HttpClient>

A delegate that is used to configure an HttpClient.

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

HttpClient instances that apply the provided configuration can be retrieved using CreateClient(String) and providing the matching name.

TClient instances constructed with the appropriate HttpClient can be retrieved from GetService(Type) (and related methods) by providing TClient as the service type.

Use DefaultName as the name to configure the default client.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

AddHttpClient<TClient>(IServiceCollection, String)

Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient.

C#
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder AddHttpClient<TClient>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, string name) where TClient : class;

Type Parameters

TClient

The type of the typed client. The type specified will be registered in the service collection as a transient service. See ITypedHttpClientFactory<TClient> for more details about authoring typed clients.

Parameters

name
String

The logical name of the HttpClient to configure.

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

HttpClient instances that apply the provided configuration can be retrieved using CreateClient(String) and providing the matching name.

TClient instances constructed with the appropriate HttpClient can be retrieved from GetService(Type) (and related methods) by providing TClient as the service type.

Use DefaultName as the name to configure the default client.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

AddHttpClient<TClient>(IServiceCollection, Action<HttpClient>)

Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient. The client name will be set to the type name of TClient.

C#
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder AddHttpClient<TClient>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Action<System.Net.Http.HttpClient> configureClient) where TClient : class;

Type Parameters

TClient

The type of the typed client. The type specified will be registered in the service collection as a transient service. See ITypedHttpClientFactory<TClient> for more details about authoring typed clients.

Parameters

configureClient
Action<HttpClient>

A delegate that is used to configure an HttpClient.

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

HttpClient instances that apply the provided configuration can be retrieved using CreateClient(String) and providing the matching name.

TClient instances constructed with the appropriate HttpClient can be retrieved from GetService(Type) (and related methods) by providing TClient as the service type.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

AddHttpClient<TClient>(IServiceCollection, Action<IServiceProvider,HttpClient>)

Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient. The client name will be set to the type name of TClient.

C#
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder AddHttpClient<TClient>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Action<IServiceProvider,System.Net.Http.HttpClient> configureClient) where TClient : class;

Type Parameters

TClient

The type of the typed client. The type specified will be registered in the service collection as a transient service. See ITypedHttpClientFactory<TClient> for more details about authoring typed clients.

Parameters

configureClient
Action<IServiceProvider,HttpClient>

A delegate that is used to configure an HttpClient.

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

HttpClient instances that apply the provided configuration can be retrieved using CreateClient(String) and providing the matching name.

TClient instances constructed with the appropriate HttpClient can be retrieved from GetService(Type) (and related methods) by providing TClient as the service type.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

AddHttpClient<TClient>(IServiceCollection)

Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs
Source:
HttpClientFactoryServiceCollectionExtensions.cs

Adds the IHttpClientFactory and related services to the IServiceCollection and configures a binding between the TClient type and a named HttpClient. The client name will be set to the type name of TClient.

C#
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder AddHttpClient<TClient>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) where TClient : class;

Type Parameters

TClient

The type of the typed client. The type specified will be registered in the service collection as a transient service. See ITypedHttpClientFactory<TClient> for more details about authoring typed clients.

Parameters

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

HttpClient instances that apply the provided configuration can be retrieved using CreateClient(String) and providing the matching name.

TClient instances constructed with the appropriate HttpClient can be retrieved from GetService(Type) (and related methods) by providing TClient as the service type.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)