Skip to main content
All docs
V24.2

StartupExtensions.AddDevExpressAI(IServiceCollection, Action<AIWebSettings>) Method

Adds DevExpress AI-related services to the application service collection.

Namespace: Microsoft.Extensions.DependencyInjection

Assembly: DevExpress.AIIntegration.Web.v24.2.dll

NuGet Package: DevExpress.AIIntegration.Web

Declaration

public static IServiceCollection AddDevExpressAI(
    this IServiceCollection collection,
    Action<AIWebSettings> configure = null
)

Parameters

Name Type Description
collection IServiceCollection

The application’s service collection.

Optional Parameters

Name Type Default Description
configure Action<AIWebSettings> null

A delegate method that configures DevExpress AI-related services for DevExpress Blazor components.

Returns

Type Description
IServiceCollection

The modified application service collection.

Remarks

Call the AddDevExpressAI(IServiceCollection, Action<AIWebSettings>) method at application startup to register an AI service and enable DevExpress AI-powered extensions in your application.

The following code snippet registers an Azure OpenAI service:

using Microsoft.Extensions.AI;
...
string azureOpenAIEndpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
string azureOpenAIKey = Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY");
string deploymentName = "gpt4o";
...
IChatClient asChatClient = new Azure.AI.OpenAI.AzureOpenAIClient(new Uri(azureOpenAIEndpoint),
    new System.ClientModel.ApiKeyCredential(azureOpenAIKey))
    .AsChatClient(deploymentName);
builder.Services.AddSingleton(asChatClient);
builder.Services.AddDevExpressAI();
See Also