From 563aa04554c33d7d559565ad7d78e777f3fc31ef Mon Sep 17 00:00:00 2001 From: Vijay Karavadra Date: Sat, 26 Mar 2022 12:02:06 +0530 Subject: [PATCH] Added AddOcelot Configbuilder Overload Added an AddOcelot overload to load FileConfiguration directly from the application, so that all the routes could be made configurable and could be load from anywhere. --- .../ConfigurationBuilderExtensions.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Ocelot/DependencyInjection/ConfigurationBuilderExtensions.cs b/src/Ocelot/DependencyInjection/ConfigurationBuilderExtensions.cs index 83e8217756..df4c53826d 100644 --- a/src/Ocelot/DependencyInjection/ConfigurationBuilderExtensions.cs +++ b/src/Ocelot/DependencyInjection/ConfigurationBuilderExtensions.cs @@ -84,5 +84,20 @@ public static IConfigurationBuilder AddOcelot(this IConfigurationBuilder builder return builder; } + + + public static IConfigurationBuilder AddOcelot( + this IConfigurationBuilder builder, FileConfiguration fileConfiguration, IWebHostEnvironment env) + { + const string primaryConfigFile = "ocelot.json"; + + var json = JsonConvert.SerializeObject(fileConfiguration); + + File.WriteAllText(primaryConfigFile, json); + + builder.AddJsonFile(primaryConfigFile, false, false); + + return builder; + } } }