Dela via


CosmosClientBuilder Class

Definition

This is a Builder class that creates a cosmos client

public class CosmosClientBuilder
type CosmosClientBuilder = class
Public Class CosmosClientBuilder
Inheritance
CosmosClientBuilder

Constructors

CosmosClientBuilder(String, AzureKeyCredential)

Initialize a new CosmosConfiguration class that holds all the properties the CosmosClient requires with the account endpoint URI string and AzureKeyCredential. AzureKeyCredential enables changing/updating master-key/ResourceToken while CosmosClient is still in use.

CosmosClientBuilder(String, String)

Initialize a new CosmosConfiguration class that holds all the properties the CosmosClient requires.

CosmosClientBuilder(String, TokenCredential)

Initializes a new CosmosClientBuilder with a TokenCredential instance.

CosmosClientBuilder(String)

Extracts the account endpoint and key from the connection string.

Methods

AddCustomHandlers(RequestHandler[])

Sets an array of custom handlers to the request. The handlers will be chained in the order listed. The InvokerHandler.InnerHandler is required to be null to allow the pipeline to chain the handlers.

Build()

A method to create the cosmos client CosmosClient is thread-safe. Its recommended to maintain a single instance of CosmosClient per lifetime of the application which enables efficient connection management and performance. Please refer to the performance guide.

BuildAndInitializeAsync(IReadOnlyList<ValueTuple<String,String>>, CancellationToken)

A method to create the cosmos client and initialize the provided containers. In addition to that it initializes the client with containers provided i.e The SDK warms up the caches and connections before the first call to the service is made. Use this to obtain lower latency while startup of your application. CosmosClient is thread-safe. Its recommended to maintain a single instance of CosmosClient per lifetime of the application which enables efficient connection management and performance. Please refer to the performance guide.

WithApplicationName(String)

A suffix to be added to the default user-agent for the Azure Cosmos DB service.

WithApplicationPreferredRegions(IReadOnlyList<String>)

Set the preferred regions for geo-replicated database accounts in the Azure Cosmos DB service.

WithApplicationRegion(String)

Set the preferred geo-replicated region to be used in the Azure Cosmos DB service.

WithBulkExecution(Boolean)

Allows optimistic batching of requests to service. Setting this option might impact the latency of the operations. Hence this option is recommended for non-latency sensitive scenarios only.

WithClientTelemetryOptions(CosmosClientTelemetryOptions)

To enable Telemetry features with corresponding options

WithConnectionModeDirect()

Sets the connection mode to Direct. This is used by the client when connecting to the Azure Cosmos DB service.

WithConnectionModeDirect(Nullable<TimeSpan>, Nullable<TimeSpan>, Nullable<Int32>, Nullable<Int32>, Nullable<PortReuseMode>, Nullable<Boolean>)

Sets the connection mode to Direct. This is used by the client when connecting to the Azure Cosmos DB service.

WithConnectionModeGateway(Nullable<Int32>, IWebProxy)

Sets the connection mode to Gateway. This is used by the client when connecting to the Azure Cosmos DB service.

WithConsistencyLevel(ConsistencyLevel)

This can be used to weaken the database account consistency level for read operations. If this is not set the database account consistency level will be used for all requests.

WithContentResponseOnWrite(Boolean)

Gets or sets the boolean to only return the headers and status code in the Cosmos DB response for write item operation like Create, Upsert, Patch and Replace. Setting the option to false will cause the response to have a null resource. This reduces networking and CPU load by not sending the resource back over the network and serializing it on the client.

WithCustomAccountEndpoints(IEnumerable<Uri>)

Sets the custom endpoints to use for account initialization for geo-replicated database accounts in the Azure Cosmos DB service. During the CosmosClient initialization the account information, including the available regions, is obtained from the Endpoint. Should the global endpoint become inaccessible, the CosmosClient will attempt to obtain the account information issuing requests to the custom endpoints provided in the customAccountEndpoints list.

WithCustomSerializer(CosmosSerializer)

Set a custom JSON serializer.

WithHttpClientFactory(Func<HttpClient>)

Sets a delegate to use to obtain an HttpClient instance to be used for HTTPS communication.

WithLimitToEndpoint(Boolean)

Limits the operations to the provided endpoint on the CosmosClientBuilder constructor.

WithPriorityLevel(PriorityLevel)

Sets the priority level for requests created using cosmos client.

WithRequestTimeout(TimeSpan)

Sets the request timeout in seconds when connecting to the Azure Cosmos DB service.

WithSerializerOptions(CosmosSerializationOptions)

Set a custom serializer option.

WithThrottlingRetryOptions(TimeSpan, Int32)

Sets the maximum time to wait between retry and the max number of times to retry on throttled requests.

Applies to