示例#1
0
        public CosmosDbBuilder WithDatabaseThroughput(int throughput)
        {
            _dbconfig = _dbconfig != null ?
                        new CosmosDbConfig(_dbconfig.DatabaseId, throughput)
                                :
                        new CosmosDbConfig(null, throughput);

            return(this);
        }
示例#2
0
        public CosmosDbClient(
            IServiceProvider serviceProvider,
            CosmosDbConnection connection,
            CosmosDbConfig dbConfig,
            IEnumerable <ContainerDefinition> containerDefinitions)
        {
            this.ServiceProvider = serviceProvider;

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

            _containerDefinitions = definitions.ToArray();

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

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

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

                return(resp.Database);
            });
        }
示例#3
0
        public CosmosDbClient(
            CosmosDbConnectionSettings connectionSettings,
            CosmosDbConfig dbConfig,
            IEnumerable <ContainerDefinition> containerDefinitions)
        {
            IEnumerable <ContainerDefinition> definitions = containerDefinitions as ContainerDefinition[] ?? containerDefinitions.ToArray();

            _containerDefinitions = definitions.ToArray();

            _sdkClient = new CosmosClient(
                connectionSettings.EndPoint,
                connectionSettings.AuthKey,
                new CosmosClientOptions()
            {
                Serializer = new ConfigurableCosmosSerializer(
                    new JsonSerializerSettings()
                {
                    NullValueHandling     = NullValueHandling.Ignore,
                    TypeNameHandling      = TypeNameHandling.All,
                    MissingMemberHandling = MissingMemberHandling.Ignore
                }),
                ConnectionMode = ConnectionMode.Direct
            });

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

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

                return(resp.Database);
            });
        }
示例#4
0
 public CosmosDbClientBuilder WithDbConfig(CosmosDbConfig config)
 {
     _dbconfig = config;
     return(this);
 }
示例#5
0
 public CosmosDbClientBuilder ReadConfiguration(IConfiguration config)
 {
     _connectionSettings = new CosmosDbConnectionSettings(config);
     _dbconfig           = new CosmosDbConfig(config);
     return(this);
 }
示例#6
0
 public CosmosDbBuilder UseDatabase(string databaseId)
 {
     _dbconfig = new CosmosDbConfig(databaseId, null);
     return(this);
 }
示例#7
0
 public CosmosDbBuilder ReadConfiguration(IConfiguration config)
 {
     _connection = new CosmosDbConnection(config);
     _dbconfig   = new CosmosDbConfig(config);
     return(this);
 }