.NET Ocelot配置文件更改时重新加载JSON配置
在项目生产环境中,每次修改Ocelot配置文件不可能都要重新启动项目使配置文件重新生效。
只要修改成如下即可:
       public static void Main(string[] args)
        {
            CreateHostBuilder(args)
                .ConfigureAppConfiguration((hostingContext, builder) => {
                    builder
                    .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
                    //ocelot 配置文件的动态更新
                    .AddJsonFile("configuration.json", optional: false, reloadOnChange: true); 
                }).Build().Run();
        }
       public void ConfigureServices(IServiceCollection services)
        {
            services.AddOcelot()
                  .AddConsul()
                  .AddPolly();
        }
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            //请求被Ocelot处理
            app.UseOcelot();
        }