AspireMicrosoftAzureCosmosExtensions.AddAzureCosmosClient Method

Definition

Registers CosmosClient as a singleton in the services provided by the builder. Configures logging and telemetry for the CosmosClient.

public static void AddAzureCosmosClient (this Microsoft.Extensions.Hosting.IHostApplicationBuilder builder, string connectionName, Action<Aspire.Microsoft.Azure.Cosmos.MicrosoftAzureCosmosSettings>? configureSettings = default, Action<Microsoft.Azure.Cosmos.CosmosClientOptions>? configureClientOptions = default);
static member AddAzureCosmosClient : Microsoft.Extensions.Hosting.IHostApplicationBuilder * string * Action<Aspire.Microsoft.Azure.Cosmos.MicrosoftAzureCosmosSettings> * Action<Microsoft.Azure.Cosmos.CosmosClientOptions> -> unit
<Extension()>
Public Sub AddAzureCosmosClient (builder As IHostApplicationBuilder, connectionName As String, Optional configureSettings As Action(Of MicrosoftAzureCosmosSettings) = Nothing, Optional configureClientOptions As Action(Of CosmosClientOptions) = Nothing)

Parameters

builder
IHostApplicationBuilder

The IHostApplicationBuilder to read config from and add services to.

connectionName
String

The connection name to use to find a connection string.

configureSettings
Action<MicrosoftAzureCosmosSettings>

An optional method that can be used for customizing the MicrosoftAzureCosmosSettings. It's invoked after the settings are read from the configuration.

configureClientOptions
Action<CosmosClientOptions>

An optional method that can be used for customizing the CosmosClientOptions.

Exceptions

If required ConnectionString is not provided in configuration section

Remarks

Reads the configuration from "Aspire:Microsoft:Azure:Cosmos" section.

Applies to