IHttpClientBuilder 接口

定义

用于配置 IHttpClientFactory 返回的已命名 HttpClient 实例的生成器。A builder for configuring named HttpClient instances returned by IHttpClientFactory.

public interface class IHttpClientBuilder
public interface IHttpClientBuilder
type IHttpClientBuilder = interface
Public Interface IHttpClientBuilder

属性

Name

获取此生成器所配置的客户端名称。Gets the name of the client configured by this builder.

Services

获取应用程序服务集合。Gets the application service collection.

扩展方法

AddHttpMessageHandler(IHttpClientBuilder, Func<IServiceProvider,DelegatingHandler>)

添加一个委托,该委托将用于为已命名的 HttpClient 创建附加消息处理程序。Adds a delegate that will be used to create an additional message handler for a named HttpClient.

AddHttpMessageHandler(IHttpClientBuilder, Func<DelegatingHandler>)

添加一个委托,该委托将用于为已命名的 HttpClient 创建附加消息处理程序。Adds a delegate that will be used to create an additional message handler for a named HttpClient.

AddHttpMessageHandler<THandler>(IHttpClientBuilder)

从已命名的 HttpClient 的依赖关系注入容器中添加附加消息处理程序。Adds an additional message handler from the dependency injection container for a named HttpClient.

AddTypedClient<TClient>(IHttpClientBuilder)

配置 TClient 类型与已命名的 HttpClient(与 IHttpClientBuilder 关联)之间的绑定。Configures a binding between the TClient type and the named HttpClient associated with the IHttpClientBuilder.

AddTypedClient<TClient>(IHttpClientBuilder, Func<HttpClient,TClient>)

配置 TClient 类型与已命名的 HttpClient(与 IHttpClientBuilder 关联)之间的绑定。Configures a binding between the TClient type and the named HttpClient associated with the IHttpClientBuilder.

AddTypedClient<TClient>(IHttpClientBuilder, Func<HttpClient,IServiceProvider,TClient>)

配置 TClient 类型与已命名的 HttpClient(与 IHttpClientBuilder 关联)之间的绑定。Configures a binding between the TClient type and the named HttpClient associated with the IHttpClientBuilder.

AddTypedClient<TClient,TImplementation>(IHttpClientBuilder)

配置 TClient 类型与已命名的 HttpClient(与 IHttpClientBuilder 关联)之间的绑定。Configures a binding between the TClient type and the named HttpClient associated with the IHttpClientBuilder. 创建的实例的类型为 TImplementationThe created instances will be of type TImplementation.

ConfigureHttpClient(IHttpClientBuilder, Action<IServiceProvider,HttpClient>)

添加用于配置已命名的 HttpClient 的委托。Adds a delegate that will be used to configure a named HttpClient.

ConfigureHttpClient(IHttpClientBuilder, Action<HttpClient>)

添加用于配置已命名的 HttpClient 的委托。Adds a delegate that will be used to configure a named HttpClient.

ConfigureHttpMessageHandlerBuilder(IHttpClientBuilder, Action<HttpMessageHandlerBuilder>)

添加一个委托,该委托将用于使用 HttpMessageHandlerBuilder 为已命名的 HttpClient 配置消息处理程序。Adds a delegate that will be used to configure message handlers using HttpMessageHandlerBuilder for a named HttpClient.

ConfigurePrimaryHttpMessageHandler(IHttpClientBuilder, Func<IServiceProvider,HttpMessageHandler>)

添加一个委托,该委托将为已命名的 HttpClient 配置主要 HttpMessageHandlerAdds a delegate that will be used to configure the primary HttpMessageHandler for a named HttpClient.

ConfigurePrimaryHttpMessageHandler(IHttpClientBuilder, Func<HttpMessageHandler>)

添加一个委托,该委托将为已命名的 HttpClient 配置主要 HttpMessageHandlerAdds a delegate that will be used to configure the primary HttpMessageHandler for a named HttpClient.

ConfigurePrimaryHttpMessageHandler<THandler>(IHttpClientBuilder)

从已命名的 HttpClient 的依赖关系注入容器中配置主要 HttpMessageHandlerConfigures the primary HttpMessageHandler from the dependency injection container for a named HttpClient.

RedactLoggedHeaders(IHttpClientBuilder, IEnumerable<String>)

设置其值应在记录之前进行修正的 HTTP 标头名称的集合。Sets the collection of HTTP header names for which values should be redacted before logging.

RedactLoggedHeaders(IHttpClientBuilder, Func<String,Boolean>)

设置用于确定是否在记录之前修正 HTTP 标头值的 Func<T,TResult>Sets the Func<T,TResult> which determines whether to redact the HTTP header value before logging.

SetHandlerLifetime(IHttpClientBuilder, TimeSpan)

设置可重复使用 HttpMessageHandler 实例的时长。Sets the length of time that a HttpMessageHandler instance can be reused. 每个已命名的客户端都可自行配置处理程序生存期值。Each named client can have its own configured handler lifetime value. 默认值为 2 分钟。The default value is two minutes. 将生存期设置为 InfiniteTimeSpan 可禁用处理程序到期。Set the lifetime to InfiniteTimeSpan to disable handler expiry.

AddPolicyHandler(IHttpClientBuilder, IAsyncPolicy<HttpResponseMessage>)

添加 PolicyHttpMessageHandler,它将使用提供的 IAsyncPolicy`1 将请求执行涵盖在内。Adds a PolicyHttpMessageHandler which will surround request execution with the provided IAsyncPolicy`1.

AddPolicyHandler(IHttpClientBuilder, Func<IServiceProvider,HttpRequestMessage,IAsyncPolicy<HttpResponseMessage>>)

添加 PolicyHttpMessageHandler,它将使用 policySelector 返回的策略将请求执行涵盖在内。Adds a PolicyHttpMessageHandler which will surround request execution with a policy returned by the policySelector.

AddPolicyHandler(IHttpClientBuilder, Func<IServiceProvider,HttpRequestMessage,String,IAsyncPolicy<HttpResponseMessage>>, Func<HttpRequestMessage,String>)

添加 PolicyHttpMessageHandler,它将使用通过执行提供的密钥选择逻辑 keySelectorpolicyFactory 返回的策略将请求执行涵盖在内Adds a PolicyHttpMessageHandler which will surround request execution with a policy returned by executing provided key selection logic keySelector and policyFactory

AddPolicyHandler(IHttpClientBuilder, Func<HttpRequestMessage,IAsyncPolicy<HttpResponseMessage>>)

添加 PolicyHttpMessageHandler,它将使用 policySelector 返回的策略将请求执行涵盖在内。Adds a PolicyHttpMessageHandler which will surround request execution with a policy returned by the policySelector.

AddPolicyHandlerFromRegistry(IHttpClientBuilder, Func<IReadOnlyPolicyRegistry<String>,HttpRequestMessage,IAsyncPolicy<HttpResponseMessage>>)

添加 PolicyHttpMessageHandler,它将使用 IReadOnlyPolicyRegistry<TKey> 返回的策略将请求执行涵盖在内。Adds a PolicyHttpMessageHandler which will surround request execution with a policy returned by the IReadOnlyPolicyRegistry<TKey>.

AddPolicyHandlerFromRegistry(IHttpClientBuilder, String)

添加 PolicyHttpMessageHandler,它将使用 IReadOnlyPolicyRegistry<TKey> 返回的策略将请求执行涵盖在内。Adds a PolicyHttpMessageHandler which will surround request execution with a policy returned by the IReadOnlyPolicyRegistry<TKey>.

AddTransientHttpErrorPolicy(IHttpClientBuilder, Func<PolicyBuilder<HttpResponseMessage>,IAsyncPolicy<HttpResponseMessage>>)

添加 PolicyHttpMessageHandler,它将使用通过执行提供的配置委托创建的 Policy 将请求执行涵盖在内。Adds a PolicyHttpMessageHandler which will surround request execution with a Policy created by executing the provided configuration delegate. 策略生成器将预先配置为针对失败的请求(带有指示暂时性故障的条件)的策略的触发器应用程序。The policy builder will be preconfigured to trigger application of the policy for requests that fail with conditions that indicate a transient failure.

适用于