Share via


AspireMicrosoftAzureCosmosExtensions.AddKeyedAzureCosmosClient Method

Definition

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

public static void AddKeyedAzureCosmosClient (this Microsoft.Extensions.Hosting.IHostApplicationBuilder builder, string name, Action<Aspire.Microsoft.Azure.Cosmos.MicrosoftAzureCosmosSettings>? configureSettings = default, Action<Microsoft.Azure.Cosmos.CosmosClientOptions>? configureClientOptions = default);
static member AddKeyedAzureCosmosClient : Microsoft.Extensions.Hosting.IHostApplicationBuilder * string * Action<Aspire.Microsoft.Azure.Cosmos.MicrosoftAzureCosmosSettings> * Action<Microsoft.Azure.Cosmos.CosmosClientOptions> -> unit
<Extension()>
Public Sub AddKeyedAzureCosmosClient (builder As IHostApplicationBuilder, name 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.

name
String

The name of the component, which is used as the ServiceKey of the service and also to retrieve the connection string from the ConnectionStrings configuration section.

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:{name}" section.

Applies to