public CosmosDbClient(
            CosmosDbConnectionSettings connectionSettings,
            CosmosDbDatabaseSettings cosmosDbConfig,
            ICosmosDbContainerFactory containerFactory,
            IEnumerable <ContainerDefinition> containerDefinitions)
        {
            _containerFactory = containerFactory;

            IEnumerable <ContainerDefinition> definitions = containerDefinitions as ContainerDefinition[] ?? containerDefinitions.ToArray();

            _containerDefinitions.AddRange(definitions);

            _sdkClient = new CosmosClient(
                connectionSettings.EndPoint,
                connectionSettings.AuthKey,
                new CosmosClientOptions()
            {
                ConnectionMode    = cosmosDbConfig.ConnectionMode,
                SerializerOptions = new CosmosSerializationOptions()
                {
                    IgnoreNullValues     = true,
                    PropertyNamingPolicy = CosmosPropertyNamingPolicy.CamelCase
                }
            });

            _lazyDatabase = new AsyncLazy <Database>(async() =>
            {
                DatabaseResponse resp = await _sdkClient.CreateDatabaseIfNotExistsAsync(cosmosDbConfig.DatabaseId, cosmosDbConfig.SharedThroughput);

                foreach (ContainerDefinition containerDefinition in definitions)
                {
                    await Internal_EnsureContainerExists(resp.Database, containerDefinition);
                }

                return(resp.Database);
            });
        }
 public CosmosDbClientBuilder WithDbConfig(CosmosDbDatabaseSettings config)
 {
     _dbconfig = config;
     return(this);
 }
 public CosmosDbClientBuilder ReadConfiguration(IConfiguration config)
 {
     _connectionSettings = new CosmosDbConnectionSettings(config);
     _dbconfig           = new CosmosDbDatabaseSettings(config);
     return(this);
 }