Пример #1
0
        private CosmosDBConnectionSettings ReadConfiguration()
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddEnvironmentVariables();

            var config         = builder.Build();
            var connectionInfo = new CosmosDBConnectionSettings
            {
                EndpointURL  = config["CosmosDBEndpoint"],
                DatabaseName = config["CosmosDBName"],
                AccessKey    = config["CosmosDBAccessKey"]
            };

            if (string.IsNullOrEmpty(connectionInfo.EndpointURL))
            {
                builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json");
                config = builder.Build();

                connectionInfo = new CosmosDBConnectionSettings
                {
                    EndpointURL  = config["CosmosDBEndpoint"],
                    DatabaseName = config["CosmosDBName"],
                    AccessKey    = config["CosmosDBAccessKey"]
                };
            }

            return(connectionInfo);
        }
Пример #2
0
 public CosmosDBContext()
 {
     Connection = ReadConfiguration();
     this.InitializeAsync(Connection.EndpointURL, Connection.AccessKey, Connection.DatabaseName).Wait();
 }