public static CosmosClient GetCosmosClient(CosmosDBAccount cosmosDBAccount)
 {
     if (!cosmosClients.ContainsKey(cosmosDBAccount.Endpoint))
     {
         CreateClient(cosmosDBAccount);
     }
     return(cosmosClients[cosmosDBAccount.Endpoint]);
 }
 public static void CreateClient(CosmosDBAccount cosmosDBAccount)
 {
     using (var lockKey = Lockkey.GetLock(lockObject, defaultTimeoutInMilliseconds))
     {
         if (!cosmosClients.ContainsKey(cosmosDBAccount.Endpoint))
         {
             cosmosClients[cosmosDBAccount.Endpoint] = new CosmosClient(cosmosDBAccount.Endpoint, cosmosDBAccount.AuthKey);
         }
     }
 }
        public static CosmosDBAccount GetCosmosDBAccount(string prefix, IConfigurationRoot configuration)
        {
            CosmosDBAccount cosmosDBAccount = new CosmosDBAccount();

            cosmosDBAccount.Endpoint                   = configuration[$"{prefix}-Endpoint"];
            cosmosDBAccount.AuthKey                    = configuration[$"{prefix}-AuthKey"];
            cosmosDBAccount.Database                   = configuration[$"{prefix}-Database"];
            cosmosDBAccount.Container                  = configuration[$"{prefix}-Container"];
            cosmosDBAccount.PartitionKeyPath           = configuration[$"{prefix}-PartitionKeyPath"];
            cosmosDBAccount.CreateIfDatabaseNotExists  = bool.Parse(configuration[$"{prefix}-CreateIfDatabaseNotExists"]);
            cosmosDBAccount.CreateIfContainerNotExists = bool.Parse(configuration[$"{prefix}-CreateIfContainerNotExists"]);
            cosmosDBAccount.DeleteIfDatabaseExists     = bool.Parse(configuration[$"{prefix}-DeleteIfDatabaseExists"]);
            cosmosDBAccount.DeleteIfContainerExists    = bool.Parse(configuration[$"{prefix}-DeleteIfContainerExists"]);
            return(cosmosDBAccount);
        }
        public static async Task SetupCosmosDBEntitiesAsync(CosmosDBAccount cosmosDBAccount)
        {
            Database database = await CosmosExtension.SetupDatabaseAsync(cosmosDBAccount.Database, cosmosDBAccount.CreateIfContainerNotExists, cosmosDBAccount.DeleteIfDatabaseExists, CosmosClientPool.GetCosmosClient(cosmosDBAccount));

            await CosmosExtension.SetupCollectionAsync(database, cosmosDBAccount.Container, cosmosDBAccount.PartitionKeyPath, cosmosDBAccount.CreateIfContainerNotExists, cosmosDBAccount.DeleteIfContainerExists);
        }