Consul作爲配置中心,配置Asp.Net Core應用程序 依據key/value自動更新
https://github.com/wintoncode/Winton.Extensions.Configuration.Consul
下載源碼,編譯
修改:Program中的consul的地址
在consul的Key/Value下增加一個
key=appsettings.json
value={"TestConfig":{"key":"King88888888","name":"dacong","title":"FMS MES"}}
運行Website
TestConfig:key
你可以自定義自己的類
[ApiController]
[Route("[controller]")]
public class HomeController : ControllerBase
{
private Configs config;
public HomeController(IOptionsSnapshot<Configs> config)
{
this.config = config.Value;
}
// GET: /<controller>/
[HttpGet("{Index}")]
public IActionResult Index()
{
return Ok(new { config });
}
}
public class Configs
{
public string Key { get; set; }
public string Name { get; set; }
public string Title { get; set; }
}