private void SetEnvironment() { IConfigurationRoot root = Configuration as IConfigurationRoot; if (root == null) { return; } MemoryConfigurationProvider provider = root.Providers.OfType <MemoryConfigurationProvider>().FirstOrDefault(); if (provider == null) { return; } string environment; if (!provider.TryGet(nameof(MessageBrokerEnvironment), out environment)) { throw new Exception("Environment not specified"); } environment = environment ?? "Test"; MessageBrokerEnvironment = environment.Parse <MessageBrokerEnvironment>(ignoreCase: true); MessageBrokerConfiguration = new ServerConfigurationManager().GetConfiguration(MessageBrokerEnvironment); }
public void IConfigurationProvider_MemoryConfigurationProvider() { var source = new MemoryConfigurationSource { InitialData = new Dictionary <string, string> { ["Name"] = "SinxHe", ["ConnectionStrings:Ali"] = "{AliConnectionString}" } }; var provider = new MemoryConfigurationProvider(source); provider.TryGet("Name", out var name0); // !!! Assert.Equal(name0, "SinxHe"); provider.Load(); provider.TryGet("Name", out var name1); Assert.Equal(name1, "SinxHe"); }