private static CosmosClient CreateCosmosClient(string connectionString, CosmosOptions cosmosOptions) { GuardEmptyString(connectionString, "cosmosDbConnectionString"); cosmosOptions.Guard(); var builder = new CosmosClientBuilder(connectionString); // ConnectionPolicy のDefault値は、SDKのConnectionPolicy.csで設定されています。 // ## Connection Mode について // Default で ConnectionMode.Direct/Protocol.Tcp で接続されます。 // もしGateway(ConnectionMode.Gateway/Protocol.Https) を使いたければ、以下メソッドを呼ぶ // builder.UseConnectionModeGateway(maxConnectionLimit: ??); // Default: CamelCase Serialize/Deserialize and ignore Readonly property // TODO: 設定変更用のconfigは未実装 //var settings = JsonSerializerSettingsFactory.CreateForReadonlyIgnoreAndCamelCase(); var settings = JsonSerializerSettingsFactory.CreateForCamelCase(); builder.UseCustomJsonSerializer(new CustomizableCaseJsonSerializer(settings)); if (cosmosOptions.ThrottlingRetryOptions != null) { builder.UseThrottlingRetryOptions(cosmosOptions.ThrottlingRetryOptions.MaxRetryWaitTimeOnThrottledRequests, cosmosOptions.ThrottlingRetryOptions.MaxRetryAttemptsOnThrottledRequests); } // multi-master support if (!string.IsNullOrEmpty(cosmosOptions.CurrentRegion)) { builder.UseCurrentRegion(cosmosOptions.CurrentRegion); } return(builder.Build()); }
public CosmosContext(CosmosClient cosmosClient, IOptions <CosmosOptions> options, ILogger <CosmosContext> logger) { _cosmosClient = cosmosClient; _logger = logger; _cosmosOptions = options.Value; _cosmosOptions.Guard(); SetupAsync().GetAwaiter().GetResult(); }