예제 #1
0
        public CosmosDbClient(
            IServiceProvider serviceProvider,
            CosmosDbConnectionSettings connectionSettings,
            CosmosDbDatabaseConfig dbDatabaseConfig,
            IEnumerable <ContainerDefinition> containerDefinitions)
        {
            this.ServiceProvider = serviceProvider;

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

            _containerDefinitions = definitions.ToArray();

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

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

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

                return(resp.Database);
            });
        }
예제 #2
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);
            });
        }
 public CosmosDbClientBuilder Connect(CosmosDbConnectionSettings connSettings)
 {
     _connectionSettings = connSettings;
     return(this);
 }
 public CosmosDbClientBuilder Connect(string endPoint, string authKey)
 {
     _connectionSettings = new CosmosDbConnectionSettings(endPoint, authKey);
     return(this);
 }
 public CosmosDbClientBuilder ReadConfiguration(IConfiguration config)
 {
     _connectionSettings = new CosmosDbConnectionSettings(config);
     _dbconfig           = new CosmosDbDatabaseSettings(config);
     return(this);
 }