ChatClientBuilderServiceCollectionExtensions.AddChatClient Method

Definition

Overloads

AddChatClient(IServiceCollection, IChatClient, ServiceLifetime)

Registers a singleton IChatClient in the IServiceCollection.

C#
public static Microsoft.Extensions.AI.ChatClientBuilder AddChatClient(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, Microsoft.Extensions.AI.IChatClient innerClient, Microsoft.Extensions.DependencyInjection.ServiceLifetime lifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton);

Parameters

serviceCollection
IServiceCollection

The IServiceCollection to which the client should be added.

innerClient
IChatClient

The inner IChatClient that represents the underlying backend.

lifetime
ServiceLifetime

The service lifetime for the client. Defaults to Singleton.

Returns

A ChatClientBuilder that can be used to build a pipeline around the inner client.

Remarks

The client is registered as a singleton service.

Applies to

.NET 10 (package-provided) och andra versioner
Produkt Versioner
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

AddChatClient(IServiceCollection, Func<IServiceProvider,IChatClient>, ServiceLifetime)

Registers a singleton IChatClient in the IServiceCollection.

C#
public static Microsoft.Extensions.AI.ChatClientBuilder AddChatClient(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, Func<IServiceProvider,Microsoft.Extensions.AI.IChatClient> innerClientFactory, Microsoft.Extensions.DependencyInjection.ServiceLifetime lifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton);

Parameters

serviceCollection
IServiceCollection

The IServiceCollection to which the client should be added.

innerClientFactory
Func<IServiceProvider,IChatClient>

A callback that produces the inner IChatClient that represents the underlying backend.

lifetime
ServiceLifetime

The service lifetime for the client. Defaults to Singleton.

Returns

A ChatClientBuilder that can be used to build a pipeline around the inner client.

Remarks

The client is registered as a singleton service.

Applies to

.NET 10 (package-provided) och andra versioner
Produkt Versioner
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)