/// <summary> /// Initialises Cosmos DB client connection and container. /// </summary> /// <param name="configurationSection"></param> /// <returns></returns> private static async Task <CosmosDBService> InitialiseCosmosClientInstanceAsync(IConfigurationSection configurationSection) { // Set connection parameters string databaseName = configurationSection.GetSection("DatabaseName").Value; string containerName = configurationSection.GetSection("ContainerName").Value; string account = configurationSection.GetSection("Account").Value; string key = configurationSection.GetSection("Key").Value; // Build client and services Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder clientBuilder = new Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder(account, key); Microsoft.Azure.Cosmos.CosmosClient client = clientBuilder.WithConnectionModeDirect().Build(); CosmosDBService dBService = new CosmosDBService(client, databaseName, containerName); // Initialise database, if required Microsoft.Azure.Cosmos.DatabaseResponse database = await client.CreateDatabaseIfNotExistsAsync(databaseName); // Build the database container await database.Database.CreateContainerIfNotExistsAsync(containerName, "/id"); return(dBService); }
private static LinkRepository InitializeCosmosClientInstance(LinkConfig linkConfig) { Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder clientBuilder = new Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder(linkConfig.ConnectionString); Microsoft.Azure.Cosmos.CosmosClient client = clientBuilder .WithConnectionModeDirect() .Build(); LinkRepository linkRepository = new LinkRepository(client, linkConfig.DatabaseName, linkConfig.ContainerName); return(linkRepository); }
private static InterUserMessageRepository InitializeCosmosClientInstance(InterUserMessageConfig interUserMessageConfig) { Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder clientBuilder = new Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder(interUserMessageConfig.ConnectionString); Microsoft.Azure.Cosmos.CosmosClient client = clientBuilder .WithConnectionModeDirect() .Build(); InterUserMessageRepository interUserMessageRepository = new InterUserMessageRepository(client, interUserMessageConfig.DatabaseName, interUserMessageConfig.ContainerName); return(interUserMessageRepository); }
private static CosmosDbService InitializeCosmosClientInstance(CosmosConfig cosmosConfig) { Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder clientBuilder = new Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder(cosmosConfig.ConnectionString); Microsoft.Azure.Cosmos.CosmosClient client = clientBuilder .WithConnectionModeDirect() .Build(); CosmosDbService cosmosDbService = new CosmosDbService(client, cosmosConfig.DatabaseName, cosmosConfig.ContainerName); return(cosmosDbService); }
/// Creates a Cosmos DB database and a container with the specified partition key. private static CosmosClient GetCosmosClientInstance() { string account = Environment.GetEnvironmentVariable("COSMOS_DB"); string key = Environment.GetEnvironmentVariable("COSMOS_DB_KEY"); Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder clientBuilder = new Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder(account, key); return(clientBuilder .WithConnectionModeDirect() .Build()); }
private static CosmosDbService InitializeCosmosClientInstance(CosmosConfig cosmosConfig) { Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder clientBuilder = new Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder(cosmosConfig.ConnectionString); Microsoft.Azure.Cosmos.CosmosClient client = clientBuilder .WithConnectionModeDirect() .Build(); CosmosDbService cosmosDbService = new CosmosDbService(client, cosmosConfig.DatabaseName, cosmosConfig.ContainerName); //Microsoft.Azure.Cosmos.DatabaseResponse database = await client.CreateDatabaseIfNotExistsAsync(databaseName); //await database.Database.CreateContainerIfNotExistsAsync(containerName, "/id"); return(cosmosDbService); }
/// <summary> /// Creates a Cosmos DB database and a container with the specified partition key. /// </summary> /// <returns></returns> private static async Task <CosmosDbService> InitializeCosmosClientInstanceAsync(CosmosConfig cosmosConfig) { var clientBuilder = new Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder(cosmosConfig.Account, cosmosConfig.Key); var client = clientBuilder .WithConnectionModeDirect() .Build(); var cosmosDbService = new CosmosDbService(client, cosmosConfig.DatabaseName, cosmosConfig.ContainerName); var database = await client.CreateDatabaseIfNotExistsAsync(cosmosConfig.DatabaseName); await database.Database.CreateContainerIfNotExistsAsync(cosmosConfig.ContainerName, "/pk"); return(cosmosDbService); }
private ConversationReferenceDao InitializeCosmosClientInstance() { string account = configuration["CosmosDbEndpoint"]; string key = configuration["CosmosDbAuthKey"]; Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder clientBuilder = new Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder(account, key); Microsoft.Azure.Cosmos.CosmosClient client = clientBuilder .WithConnectionModeDirect() .Build(); ConversationReferenceDao cosmosDbService = new ConversationReferenceDao(client, configuration); return(cosmosDbService); }
/// Creates a Cosmos DB database and a container with the specified partition key. private static CosmosDBService InitializeCosmosClientInstanceAsync(IConfigurationSection configurationSection) { string databaseName = configurationSection.GetSection("DatabaseName").Value; string containerName = configurationSection.GetSection("ContainerName").Value; string account = configurationSection.GetSection("Account").Value; string key = configurationSection.GetSection("Key").Value; Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder clientBuilder = new Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder(account, key); Microsoft.Azure.Cosmos.CosmosClient client = clientBuilder .WithConnectionModeDirect() .Build(); CosmosDBService cosmosDbService = new CosmosDBService(client, databaseName); client.CreateDatabaseIfNotExistsAsync(databaseName); return(cosmosDbService); }
private async Task <CosmosClient> InitializeCosmosClientInstanceAsync() { var cosmosSection = Configuration.GetSection("CosmosDb"); string databaseName = cosmosSection.GetSection("DatabaseName").Value; string containerName = cosmosSection.GetSection("ContainerName").Value; string account = cosmosSection.GetSection("Account").Value; string key = cosmosSection.GetSection("Key").Value; var clientBuilder = new Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder(account, key); var client = clientBuilder .WithConnectionModeDirect() .Build(); var database = await client.CreateDatabaseIfNotExistsAsync(databaseName); await database.Database.CreateContainerIfNotExistsAsync(containerName, "/_partitionKey"); return(client); }
private static async Task <CosmosDbImpl> InitializeCosmosClientInstanceAsync(IConfigurationSection configurationSection) { string databaseName = configurationSection.GetSection("DatabaseName").Value; string containerName = configurationSection.GetSection("ContainerName").Value; string account = configurationSection.GetSection("Account").Value; string key = configurationSection.GetSection("Key").Value; Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder clientBuilder = new Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder(account, key); Microsoft.Azure.Cosmos.CosmosClient client = clientBuilder .WithConnectionModeDirect() .Build(); CosmosDbImpl cosmosDbService = new CosmosDbImpl(client, databaseName, containerName); Microsoft.Azure.Cosmos.DatabaseResponse database = await client.CreateDatabaseIfNotExistsAsync(databaseName); await database.Database.CreateContainerIfNotExistsAsync(containerName, "/legendname"); return(cosmosDbService); }