Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose more CosmosClient options #21281

Merged
merged 1 commit into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 87 additions & 3 deletions src/EFCore.Cosmos/Infrastructure/CosmosDbContextOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.ComponentModel;
using System.Net;
using JetBrains.Annotations;
using Microsoft.Azure.Cosmos;
using Microsoft.EntityFrameworkCore.Cosmos.Infrastructure.Internal;
Expand Down Expand Up @@ -45,19 +46,102 @@ public virtual CosmosDbContextOptionsBuilder ExecutionStrategy(
=> WithOption(e => e.WithExecutionStrategyFactory(Check.NotNull(getExecutionStrategy, nameof(getExecutionStrategy))));

/// <summary>
/// Configures the context to use the provided Region.
/// Configures the context to use the provided geo-replicated region.
/// </summary>
/// <param name="region">CosmosDB region name</param>
/// <param name="region"> Azure Cosmos DB region name. </param>
public virtual CosmosDbContextOptionsBuilder Region([NotNull] string region)
=> WithOption(e => e.WithRegion(Check.NotNull(region, nameof(region))));

/// <summary>
/// Limits the operations to the provided endpoint.
/// </summary>
/// <param name="enable"> <see langword="true"/> to limit the operations to the provided endpoint. </param>
public virtual CosmosDbContextOptionsBuilder LimitToEndpoint(bool enable = true)
=> WithOption(e => e.WithLimitToEndpoint(Check.NotNull(enable, nameof(enable))));

/// <summary>
/// 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.
/// </summary>
/// <param name="enable"> <see langword="true"/> to allow optimistic batching of requests to service. </param>
public virtual CosmosDbContextOptionsBuilder AllowBulkExecution(bool enable = true)
=> WithOption(e => e.WithAllowBulkExecution(Check.NotNull(enable, nameof(enable))));

/// <summary>
/// Configures the context to use the provided connection mode.
/// </summary>
/// <param name="connectionMode">CosmosDB connection mode</param>
/// <param name="connectionMode"> Azure Cosmos DB connection mode. </param>
public virtual CosmosDbContextOptionsBuilder ConnectionMode(ConnectionMode connectionMode)
=> WithOption(e => e.WithConnectionMode(Check.NotNull(connectionMode, nameof(connectionMode))));

/// <summary>
/// Configures the proxy information used for web requests.
/// </summary>
/// <param name="proxy"> The proxy information used for web requests. </param>
public virtual CosmosDbContextOptionsBuilder WebProxy([NotNull] IWebProxy proxy)
=> WithOption(e => e.WithWebProxy(Check.NotNull(proxy, nameof(proxy))));

/// <summary>
/// Configures the timeout when connecting to the Azure Cosmos DB service.
/// The number specifies the time to wait for response to come back from network peer.
/// </summary>
/// <param name="timeout"> Request timeout. </param>
public virtual CosmosDbContextOptionsBuilder RequestTimeout(TimeSpan timeout)
=> WithOption(e => e.WithRequestTimeout(Check.NotNull(timeout, nameof(timeout))));

/// <summary>
/// Configures the amount of time allowed for trying to establish a connection.
/// </summary>
/// <param name="timeout"> Open TCP connection timeout. </param>
public virtual CosmosDbContextOptionsBuilder OpenTcpConnectionTimeout(TimeSpan timeout)
=> WithOption(e => e.WithOpenTcpConnectionTimeout(Check.NotNull(timeout, nameof(timeout))));

/// <summary>
/// Configures the amount of idle time after which unused connections are closed.
/// </summary>
/// <param name="timeout"> Idle connection timeout. </param>
public virtual CosmosDbContextOptionsBuilder IdleTcpConnectionTimeout(TimeSpan timeout)
=> WithOption(e => e.WithIdleTcpConnectionTimeout(Check.NotNull(timeout, nameof(timeout))));

/// <summary>
/// Configures the client port reuse policy used by the transport stack.
/// </summary>
/// <param name="portReuseMode"> The client port reuse policy used by the transport stack. </param>
public virtual CosmosDbContextOptionsBuilder PortReuseMode(PortReuseMode portReuseMode)
=> WithOption(e => e.WithPortReuseMode(Check.NotNull(portReuseMode, nameof(portReuseMode))));

/// <summary>
/// Configures the context to enable address cache refresh on TCP connection reset notification.
/// </summary>
/// <param name="enabled"> <see langword="true"/> to enable address cache refresh on TCP connection reset notification. </param>
public virtual CosmosDbContextOptionsBuilder EnableTcpConnectionEndpointRediscovery(bool enabled = true)
=> WithOption(e => e.WithTcpConnectionEndpointRediscovery(Check.NotNull(enabled, nameof(enabled))));

/// <summary>
/// Configures the maximum number of concurrent connections allowed for the target service endpoint
/// in the Azure Cosmos DB service.
/// </summary>
/// <param name="connectionLimit"> The maximum number of concurrent connections allowed. </param>
public virtual CosmosDbContextOptionsBuilder GatewayModeMaxConnectionLimit(int connectionLimit)
=> WithOption(e => e.WithGatewayModeMaxConnectionLimit(Check.NotNull(connectionLimit, nameof(connectionLimit))));

/// <summary>
/// Configures the maximum number of TCP connections that may be opened to each Cosmos DB back-end.
/// Together with MaxRequestsPerTcpConnection, this setting limits the number of requests that are
/// simultaneously sent to a single Cosmos DB back-end (MaxRequestsPerTcpConnection x MaxTcpConnectionPerEndpoint).
/// </summary>
/// <param name="connectionLimit"> The maximum number of TCP connections that may be opened to each Cosmos DB back-end. </param>
public virtual CosmosDbContextOptionsBuilder MaxTcpConnectionsPerEndpoint(int connectionLimit)
=> WithOption(e => e.WithMaxTcpConnectionsPerEndpoint(Check.NotNull(connectionLimit, nameof(connectionLimit))));

/// <summary>
/// Configures the number of requests allowed simultaneously over a single TCP connection.
/// When more requests are in flight simultaneously, the direct/TCP client will open additional connections.
/// </summary>
/// <param name="requestLimit"> The number of requests allowed simultaneously over a single TCP connection. </param>
public virtual CosmosDbContextOptionsBuilder MaxRequestsPerTcpConnection(int requestLimit)
=> WithOption(e => e.WithMaxRequestsPerTcpConnection(Check.NotNull(requestLimit, nameof(requestLimit))));

/// <summary>
/// Sets an option by cloning the extension used to store the settings. This ensures the builder
/// does not modify options that are already in use elsewhere.
Expand Down
Loading