Consul作爲配置中心,配置Asp.Net Core應用程序 依據key/value動態更新

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; }
    }

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章