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)

Extracts the account endpoint and key from the connection string.

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.

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

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.

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.

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.

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