Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ocelot with multiple Configuration files and Environments

Is there any way to use Ocelot with multiple Configuration files and environments like ocelot.service1.Development.json?

Unfortunately the documentation seems to be outdated and also it doesn't handle my specific request. I saw that it is able to have multiple files that will be merged Documentation:

ocelot.service1.json
ocelot.service2.json

//Program.cs
return WebHost.CreateDefaultBuilder(args)
    .ConfigureAppConfiguration((host, config) => {
        config
            .AddOcelot(host.HostingEnvironment)
            .AddEnvironmentVariables();
    })
    .UseStartup<Startup>();
}

It works but doesn't meet my requirements.

The documentation also describes following setup Documentation:

ocelot.Development.json
ocelot.Staging.json

//Program.cs
return WebHost.CreateDefaultBuilder(args)
    .ConfigureAppConfiguration((host, config) => {
        config
            .AddJsonFile("ocelot.{host.HostingEnvironment.EnvironmentName}.json", true, true)
            .AddEnvironmentVariables();
    })
    .UseStartup<Startup>();
}

But this solution also doesn't meet my requirements.

Is there any way how I can combine both ways?

like image 473
SNO Avatar asked Sep 20 '25 06:09

SNO


1 Answers

I've come up with a solution:

I edited the extension method .AddOcelot(folder, env). I've added a new parameter appNames which is an array of the names in the files to read from appName.ocelot.Dev.json to find the files.

Screenshots:

  1. program.cs
  2. File structure
  3. Modified Extension
like image 171
Arthur Muller Avatar answered Sep 23 '25 14:09

Arthur Muller