ConfigurationBuilder

We found 10 examples in language CSharp for this search. You will see 28 fragments of code.

        public static IHomeAssistantMqttConfigurationBuilder AddLight(
            this IHomeAssistantMqttConfigurationBuilder configurationBuilder,
            ILightMqttEntityConfiguration mqttEntityConfiguration)
        {
            configurationBuilder.TryRegisterEntityBindingManager<ILightMqttEntityConfiguration, ILight, ILightEntityDefinition>();

            configurationBuilder.ServiceCollection.AddSingleton(mqttEntityConfiguration);
            return configurationBuilder;
        }

        public static IHomeAssistantMqttConfigurationBuilder AddLock(
            this IHomeAssistantMqttConfigurationBuilder configurationBuilder,
            ILockMqttEntityConfiguration mqttEntityConfiguration)
        {
            configurationBuilder.TryRegisterEntityBindingManager<ILockMqttEntityConfiguration, ILock, ILockEntityDefinition>();

            configurationBuilder.ServiceCollection.AddSingleton(mqttEntityConfiguration);
            return configurationBuilder;
        }

        public static IConfigurationRoot BuilderOnly()
        {
            var configurationBuilder = new ConfigurationBuilder();

            // ... add providers

            var configuration = configurationBuilder.Build();

            return configuration;
        }

        public static IConfigurationRoot FileIni()
        {
            var configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.SetBasePath(AppDomain.CurrentDomain.BaseDirectory);

            configurationBuilder.AddIniFile("appsettings.ini", false, true);

            var configuration = configurationBuilder.Build();

            return configuration;
        }

        public static IConfigurationRoot FileJson()
        {
            var configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.SetBasePath(AppDomain.CurrentDomain.BaseDirectory);

            configurationBuilder.AddJsonFile("appsettings.json", false, true);

            var configuration = configurationBuilder.Build();

            return configuration;
        }

        public static IConfigurationRoot FileXml()
        {
            var configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.SetBasePath(AppDomain.CurrentDomain.BaseDirectory);

            configurationBuilder.AddXmlFile("appsettings.xml", false, true);

            var configuration = configurationBuilder.Build();

            return configuration;
        }

        public static IConfigurationRoot UserSecrets()
        {
            // to initialise your local store with values
            // type .\appsettings.json | dotnet user-secrets set

            var configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddUserSecrets<Program>();

            var configuration = configurationBuilder.Build();

            return configuration;
        }


        [Fact]
        public void EmptyStringIsNullable()
        {
            var dic = new Dictionary<string, string>
            {
                {"empty", ""},
            };
            var configurationBuilder = new ConfigurationBuilder();
            configurationBuilder.AddInMemoryCollection(dic);
            var config = configurationBuilder.Build();

            Assert.Null(config.GetValue<bool?>("empty"));
            Assert.Null(config.GetValue<int?>("empty"));
        }

        [Fact]
        public void BinderIgnoresIndexerProperties()
        {
            var configurationBuilder = new ConfigurationBuilder();
            var config = configurationBuilder.Build();
            config.Bind(new List<string>());
        }


        [Fact]
        public void SetValueThrowsExceptionNoSourceRegistered()
        {
            // Arrange
            var configurationBuilder = new ConfigurationBuilder();
            var config = configurationBuilder.Build();

            var expectedMsg = Resources.Error_NoSources;

            // Act
            var ex = Assert.Throws<InvalidOperationException>(() => config["Title"] = "Welcome");

            // Assert
            Assert.Equal(expectedMsg, ex.Message);
        }

        [Fact]
        public void SameReloadTokenIsReturnedRepeatedly()
        {
            // Arrange
            var configurationBuilder = new ConfigurationBuilder();
            var config = configurationBuilder.Build();

            // Act
            var token1 = config.GetReloadToken();
            var token2 = config.GetReloadToken();

            // Assert
            Assert.Same(token1, token2);
        }

        public static IConfigurationRoot ParameterStore()
        {
            var configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddSystemsManager("/emg", new AWSOptions { Region = RegionEndpoint.EUWest1 });

            var configuration = configurationBuilder.Build();

            return configuration;
        }

        public static IConfigurationRoot ECSContainerMetadata()
        {
            var configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddECSMetadataFile();

            var configuration = configurationBuilder.Build();

            return configuration;
        }

        public static IConfigurationRoot SecretsManager()
        {
            var configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddSecretsManager(region: RegionEndpoint.EUWest1);

            var configuration = configurationBuilder.Build();

            return configuration;
        }

        public static IHomeAssistantClientConfigurationBuilder WithStateDeserializer<TStateDeserializer>(this IHomeAssistantClientConfigurationBuilder configurationBuilder)
            where TStateDeserializer : class, IStateDeserializer
        {
            configurationBuilder.ServiceCollection.AddSingleton<IStateDeserializer, TStateDeserializer>();
            return configurationBuilder;
        }

        public static IHomeAssistantClientConfigurationBuilder WithEntityStateDeserializer<TEntityStateDeserializer>(this IHomeAssistantClientConfigurationBuilder configurationBuilder)
            where TEntityStateDeserializer : class, IEntityStateDeserializer
        {
            configurationBuilder.ServiceCollection.AddSingleton<IEntityStateDeserializer, TEntityStateDeserializer>();
            return configurationBuilder;
        }

        public static IHomeAssistantClientConfigurationBuilder WithStateCodeGenerator(this IHomeAssistantClientConfigurationBuilder configurationBuilder)
        {
            configurationBuilder.ServiceCollection.AddSingleton<IStateCodeGenerator, StateCodeGenerator>();
            return configurationBuilder;
        }

        public static IHomeAssistantClientConfigurationBuilder WithStateCodeGenerator<TStateCodeGenerator>(this IHomeAssistantClientConfigurationBuilder configurationBuilder)
            where TStateCodeGenerator : class, IStateCodeGenerator
        {
            configurationBuilder.ServiceCollection.AddSingleton<IStateCodeGenerator, TStateCodeGenerator>();
            return configurationBuilder;
        }


        [Fact]
        public void EmptyStringIsNullable()
        {
            var dic = new Dictionary<string, string>
            {
                {"empty", ""},
            };
            var configurationBuilder = new ConfigurationBuilder();
            configurationBuilder.AddInMemoryCollection(dic);
            var config = configurationBuilder.Build();

            Assert.Null(config.GetValue<bool?>("empty"));
            Assert.Null(config.GetValue<int?>("empty"));
        }

        [Fact]
        public void BinderIgnoresIndexerProperties()
        {
            var configurationBuilder = new ConfigurationBuilder();
            var config = configurationBuilder.Build();
            config.Bind(new List<string>());
        }


        [Fact]
        public void SetValueThrowsExceptionNoSourceRegistered()
        {
            // Arrange
            var configurationBuilder = new ConfigurationBuilder();
            var config = configurationBuilder.Build();

            var expectedMsg = Resources.Error_NoSources;

            // Act
            var ex = Assert.Throws<InvalidOperationException>(() => config["Title"] = "Welcome");

            // Assert
            Assert.Equal(expectedMsg, ex.Message);
        }

        [Fact]
        public void SameReloadTokenIsReturnedRepeatedly()
        {
            // Arrange
            var configurationBuilder = new ConfigurationBuilder();
            var config = configurationBuilder.Build();

            // Act
            var token1 = config.GetReloadToken();
            var token2 = config.GetReloadToken();

            // Assert
            Assert.Same(token1, token2);
        }

        /// <summary>
        /// Adds the memory configuration provider to <paramref name="configurationBuilder"/>.
        /// </summary>
        /// <param name="configurationBuilder">The <see cref="IConfigurationBuilder"/> to add to.</param>
        /// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
        public static IConfigurationBuilder AddInMemoryCollection(this IConfigurationBuilder configurationBuilder)
        {
            if (configurationBuilder == null)
            {
                throw new ArgumentNullException(nameof(configurationBuilder));
            }

            configurationBuilder.Add(new MemoryConfigurationSource());
            return configurationBuilder;
        }

        /// <summary>
        /// Adds the memory configuration provider to <paramref name="configurationBuilder"/>.
        /// </summary>
        /// <param name="configurationBuilder">The <see cref="IConfigurationBuilder"/> to add to.</param>
        /// <param name="initialData">The data to add to memory configuration provider.</param>
        /// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
        public static IConfigurationBuilder AddInMemoryCollection(
            this IConfigurationBuilder configurationBuilder,
            IEnumerable<KeyValuePair<string, string>> initialData)
        {
            if (configurationBuilder == null)
            {
                throw new ArgumentNullException(nameof(configurationBuilder));
            }

            configurationBuilder.Add(new MemoryConfigurationSource { InitialData = initialData });
            return configurationBuilder;
        }

    public static Dictionary<string, string> GetSwitchMappings(IReadOnlyDictionary<string, string> configurationStrings)
    {
      return configurationStrings
        .Select(item => new KeyValuePair<string, string>("-" + item.Key.Substring(item.Key.LastIndexOf(':') + 1), item.Key))
        .ToDictionary(item => item.Key, item => item.Value);
    }
    public static IConfiguration GetInMemoryConfiguration()
    {
      ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
      configurationBuilder.AddInMemoryCollection(InMemoryConfiguration);
      return configurationBuilder.Build();
    }
    public static IConfiguration GetInMemoryConfiguration(string[] args)
    {
      ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
      configurationBuilder
        .AddInMemoryCollection(InMemoryConfiguration)
        .AddCommandLine(args, GetSwitchMappings(InMemoryConfiguration));
      return configurationBuilder.Build();
    }
    public static AppConfiguration GetApplicationConfiguration(IConfiguration configuration)
    {
      AppConfiguration appConfiguration = configuration.Get<AppConfiguration>();
      return appConfiguration;
    }

LaunchDarkly.Sdk.Server.ConfigurationBuilder : Object

Methods :

public Configuration Build()
public ConfigurationBuilder BigSegments(IBigSegmentsConfigurationFactory bigSegmentsConfigurationFactory = )
public ConfigurationBuilder DataSource(IDataSourceFactory dataSourceFactory = )
public ConfigurationBuilder DataStore(IDataStoreFactory dataStoreFactory = )
public ConfigurationBuilder DiagnosticOptOut(Boolean diagnosticOptOut = )
public ConfigurationBuilder Events(IEventProcessorFactory eventProcessorFactory = )
public ConfigurationBuilder Http(IHttpConfigurationFactory httpConfigurationFactory = )
public ConfigurationBuilder Logging(ILoggingConfigurationFactory loggingConfigurationFactory = )
public ConfigurationBuilder Logging(ILogAdapter logAdapter = )
public ConfigurationBuilder Offline(Boolean offline = )
public ConfigurationBuilder SdkKey(String sdkKey = )
public ConfigurationBuilder ServiceEndpoints(ServiceEndpointsBuilder serviceEndpointsBuilder = )
public ConfigurationBuilder StartWaitTime(TimeSpan startWaitTime = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()

Other methods