Configuration center based on consul.
Package | NuGet |
---|---|
Extensions.Configuration.Consul |
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args).ConfigureAppConfiguration((context, config) =>
{
config.AddConsul("http://127.0.0.1:8500");
}).UseStartup<Startup>();
}
Command | Describetion |
---|---|
consul-configuration-addr | Consul agent address |
consul-configuration-token | ACL Token HTTP API |
consul-configuration-dc | Consul data center |
consul-configuration-folder | Prefix of key |
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args).ConfigureAppConfiguration((context, config) =>
{
config.AddConsul(args);
}).UseStartup<Startup>();
}
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddConsulConfigurationCenter();
services.AddOptions();
services.Configure<Configs>(Configuration.GetSection("TestConfig"));
}
public class LibClass
{
private Configs Config;
public LibClass(IOptionsSnapshot<Configs> config)
{
Config = config.Value;
}
public Configs Get()
{
return Config;
}
}
public class SingleClass
{
private Configs Config;
public SingleClass(IOptionsMonitor<Configs> config)
{
Config = config.CurrentValue;
config.OnChange(conf =>
{
Config = conf;
});
}
public Configs Get()
{
return Config;
}
}