Example #1
0
        private void InitializeConfigurationSettings(string configPrefix, CosmosDBClientSettings settings, IConfiguration config)
        {
            if (configPrefix == null)
            {
                throw new ArgumentNullException(nameof(configPrefix));
            }

            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var clientConfigsection = config.GetSection(configPrefix);

            if (clientConfigsection.Exists())
            {
                clientConfigsection.Bind(settings);
            }

            if (!string.IsNullOrEmpty(settings.ConnectionString))
            {
                var cs = new CosmosDBConnectionString(settings.ConnectionString);
                settings.EndpointUrl = cs.ServiceEndpoint.ToString();
                settings.PrimaryKey  = cs.AuthKey;
            }
        }
Example #2
0
        public static IConfigurationBuilder AddCosmosDB(
            this IConfigurationBuilder configurationBuilder,
            Action <CosmosDBClientSettings, IConfiguration> setterFn)
        {
            var settings = new CosmosDBClientSettings();

            setterFn.Invoke(settings, configurationBuilder.Build());

            return(configurationBuilder.AddCosmosDB(settings));
        }
Example #3
0
        public static IConfigurationBuilder AddCosmosDB(
            this IConfigurationBuilder configurationBuilder, CosmosDBClientSettings defaultSettings)
        {
            if (defaultSettings == null)
            {
                throw new ArgumentNullException(nameof(defaultSettings));
            }

            configurationBuilder.Add(new CosmosDBConfigurationProvider(defaultSettings));
            return(configurationBuilder);
        }
Example #4
0
 public CosmosDBConfigurationProvider(CosmosDBClientSettings settings)
 {
     _settings = settings ?? throw new ArgumentNullException(nameof(settings));
 }