Table of Contents

Class HttpClientFactoryService

Namespace
FoundationaLLM.Common.Services.API
Assembly
FoundationaLLM.Common.dll

Supports all classes in the .NET class hierarchy and provides low-level services to derived classes. This is the ultimate base class of all .NET classes; it is the root of the type hierarchy.

public class HttpClientFactoryService : IHttpClientFactoryService
Inheritance
HttpClientFactoryService
Implements
Inherited Members
Extension Methods

Constructors

HttpClientFactoryService(IServiceProvider, IConfiguration, IHttpClientFactory)

Creates a new instance of the HttpClientFactoryService class.

public HttpClientFactoryService(IServiceProvider serviceProvider, IConfiguration configuration, IHttpClientFactory httpClientFactory)

Parameters

serviceProvider IServiceProvider

The IServiceProvider for the main DI container.

configuration IConfiguration

The IConfiguration used to retrieve app settings from configuration.

httpClientFactory IHttpClientFactory

A fully configured IHttpClientFactory.

Exceptions

ArgumentNullException

Methods

CreateClient(APIEndpointConfiguration, UnifiedUserIdentity?)

Creates a HttpClient instance based on the endpoint configuration.

public Task<HttpClient> CreateClient(APIEndpointConfiguration endpointConfiguration, UnifiedUserIdentity? userIdentity)

Parameters

endpointConfiguration APIEndpointConfiguration

The APIEndpointConfiguration resource used to create the client.

userIdentity UnifiedUserIdentity

The UnifiedUserIdentity of the caller requesting the client.

Returns

Task<HttpClient>

An HttpClient instance.

CreateClient(string, UnifiedUserIdentity)

Creates a HttpClient instance based on the client name. The client name must be registered in the IHttpClientFactory configuration.

public Task<HttpClient> CreateClient(string clientName, UnifiedUserIdentity userIdentity)

Parameters

clientName string

The name of the HTTP client to create. This name must be registered as an APIEndpointConfiguration resource in the FoundationaLLM.Configuration resource provider.

userIdentity UnifiedUserIdentity

The UnifiedUserIdentity of the caller requesting the client.

Returns

Task<HttpClient>

An HttpClient instance.

CreateClientForStatus(string, UnifiedUserIdentity)

Creates a HttpClient instance based on the client name and sets the base address to the status endpoint. The client name must be registered in the IHttpClientFactory configuration.

public Task<HttpClient> CreateClientForStatus(string clientName, UnifiedUserIdentity userIdentity)

Parameters

clientName string

The name of the HTTP client to create. This name must be registered as an APIEndpointConfiguration resource in the FoundationaLLM.Configuration resource provider.

userIdentity UnifiedUserIdentity

The UnifiedUserIdentity of the caller requesting the client.

Returns

Task<HttpClient>

An HttpClient instance.

Exceptions

Exception

When if the service base address is null or the status endpoint is null or empty.

CreateClient<T>(string, UnifiedUserIdentity, Func<Dictionary<string, object>, T>, Dictionary<string, object>?)

Creates a T client instance based on the client name and a client builder delegate.

public Task<T> CreateClient<T>(string clientName, UnifiedUserIdentity userIdentity, Func<Dictionary<string, object>, T> clientBuilder, Dictionary<string, object>? clientBuilderParameters = null)

Parameters

clientName string

The name of the HTTP client to create. This name must be registered as an APIEndpointConfiguration resource in the FoundationaLLM.Configuration resource provider.

userIdentity UnifiedUserIdentity

The UnifiedUserIdentity of the caller requesting the client.

clientBuilder Func<Dictionary<string, object>, T>

A delegate that creates the T client instance based on a dictionary of values. The keys available in the dictionary are defined in HttpClientFactoryServiceKeyNames.

clientBuilderParameters Dictionary<string, object>

A dictionary of parameters to pass to the client builder delegate.

Returns

Task<T>

A T client instance.

Type Parameters

T

The type of the client to create.

CreateUnregisteredClient(TimeSpan?)

Creates a new unregistered HttpClient instance with a timeout.

public HttpClient CreateUnregisteredClient(TimeSpan? timeout = null)

Parameters

timeout TimeSpan?

The timeout for the HttpClient. If not specified, the default timeout in seconds is applied. For an infinite waiting period, use InfiniteTimeSpan

Returns

HttpClient

An HttpClient instance.