【发布时间】:2020-06-23 10:30:12
【问题描述】:
我正在尝试构建自己的微服务架构,但被困在 API.Gateway 部分。 我正在尝试让 Ocelot V14 在 .sln 文件中找到所有配置 ocelot.json 或 configuration.json 文件。
在 Program.cs 文件中,我尝试将配置文件与来自此链接https://ocelot.readthedocs.io/en/latest/features/configuration.html#react-to-configuration-changes
的以下代码合并builder.ConfigureServices(s => s.AddSingleton(builder))
.ConfigureAppConfiguration((hostingContext, config) =>
{
config
.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
.AddJsonFile("appsettings.json", true, true)
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
.AddOcelot(hostingContext.HostingEnvironment)
.AddEnvironmentVariables();
})
.UseStartup<Startup>();
当我运行此应用程序时,应用程序会在我的 OcelotApiGw 项目
中创建以下 ocelot.json 文件{
"ReRoutes": [
]
}
问题是它是空的,并且重新路由不起作用。当我将所需的重新路由粘贴到此 ocelot.json 文件中时,重新路由工作,这不是我想要的功能。
我想要的是从不同的 .json 文件中自动合并配置文件。
任何帮助将不胜感激。
eShopOnContainers 如何使用 Ocelot V12 以这种方式实现它
IWebHostBuilder builder = WebHost.CreateDefaultBuilder(args);
builder.ConfigureServices(s => s.AddSingleton(builder))
.ConfigureAppConfiguration(ic => ic.AddJsonFile(Path.Combine("configuration", "configuration.json")))
.UseStartup<Startup>();
如果您需要更多代码、文件结构或其他任何内容,请发表评论并询问。
【问题讨论】:
标签: docker microservices ocelot