|
3 | 3 | using Microsoft.Extensions.Configuration.Memory;
|
4 | 4 | using Ocelot.Configuration.File;
|
5 | 5 | using Ocelot.Infrastructure;
|
6 |
| -using System.Text; |
7 | 6 | using System.Text.Json;
|
8 | 7 |
|
9 | 8 | namespace Ocelot.DependencyInjection;
|
@@ -92,8 +91,8 @@ public static IConfigurationBuilder AddOcelot(this IConfigurationBuilder builder
|
92 | 91 | private static IConfigurationBuilder ApplyMergeOcelotJsonOption(IConfigurationBuilder builder, MergeOcelotJson mergeTo, string json,
|
93 | 92 | string primaryConfigFile, bool? optional, bool? reloadOnChange)
|
94 | 93 | {
|
95 |
| - return mergeTo == MergeOcelotJson.ToMemory ? |
96 |
| - builder.AddJsonStream(new MemoryStream(Encoding.UTF8.GetBytes(json))) : |
| 94 | + return mergeTo == MergeOcelotJson.ToMemory ? |
| 95 | + builder.AddJsonStream(new MemoryStream(Encoding.UTF8.GetBytes(json))) : |
97 | 96 | AddOcelotJsonFile(builder, json, primaryConfigFile, optional, reloadOnChange);
|
98 | 97 | }
|
99 | 98 |
|
@@ -133,38 +132,38 @@ private static string GetMergedOcelotJson(string folder, IWebHostEnvironment env
|
133 | 132 | continue;
|
134 | 133 | }
|
135 | 134 |
|
136 |
| - var lines = File.ReadAllText(file.FullName); |
137 |
| - var config = JsonSerializer.Deserialize<FileConfiguration>(lines, JsonSerializerOptionsFactory.Web); |
138 |
| - if (file.Name.Equals(globalFileInfo.Name, StringComparison.OrdinalIgnoreCase) && |
139 |
| - file.FullName.Equals(globalFileInfo.FullName, StringComparison.OrdinalIgnoreCase)) |
140 |
| - { |
141 |
| - fileConfiguration.GlobalConfiguration = config.GlobalConfiguration; |
142 |
| - } |
| 135 | + var lines = File.ReadAllText(file.FullName); |
| 136 | + var config = JsonSerializer.Deserialize<FileConfiguration>(lines, JsonSerializerOptionsFactory.Web); |
| 137 | + if (file.Name.Equals(globalFileInfo.Name, StringComparison.OrdinalIgnoreCase) && |
| 138 | + file.FullName.Equals(globalFileInfo.FullName, StringComparison.OrdinalIgnoreCase)) |
| 139 | + { |
| 140 | + fileConfiguration.GlobalConfiguration = config.GlobalConfiguration; |
| 141 | + } |
143 | 142 |
|
144 | 143 | fileConfiguration.Aggregates.AddRange(config.Aggregates);
|
145 | 144 | fileConfiguration.Routes.AddRange(config.Routes);
|
146 | 145 | }
|
147 | 146 |
|
148 |
| - return JsonSerializer.Serialize(fileConfiguration, JsonSerializerOptionsFactory.WebWriteIndented); |
149 |
| - } |
150 |
| - |
151 |
| - /// <summary> |
152 |
| - /// Adds Ocelot configuration by ready configuration object and writes JSON to the primary configuration file.<br/> |
153 |
| - /// Finally, adds JSON file as configuration provider. |
154 |
| - /// </summary> |
155 |
| - /// <remarks>Use optional arguments for injections and overridings.</remarks> |
156 |
| - /// <param name="builder">Configuration builder to extend.</param> |
157 |
| - /// <param name="fileConfiguration">File configuration to add as JSON provider.</param> |
158 |
| - /// <param name="primaryConfigFile">Primary config file.</param> |
159 |
| - /// <param name="optional">The 2nd argument of the AddJsonFile.</param> |
160 |
| - /// <param name="reloadOnChange">The 3rd argument of the AddJsonFile.</param> |
161 |
| - /// <returns>An <see cref="IConfigurationBuilder"/> object.</returns> |
162 |
| - public static IConfigurationBuilder AddOcelot(this IConfigurationBuilder builder, FileConfiguration fileConfiguration, |
163 |
| - string primaryConfigFile = null, bool? optional = null, bool? reloadOnChange = null) // optional injections |
164 |
| - { |
165 |
| - var json = JsonSerializer.Serialize(fileConfiguration, JsonSerializerOptionsFactory.WebWriteIndented); |
166 |
| - return AddOcelotJsonFile(builder, json, primaryConfigFile, optional, reloadOnChange); |
167 |
| - } |
| 147 | + return JsonSerializer.Serialize(fileConfiguration, JsonSerializerOptionsFactory.WebWriteIndented); |
| 148 | + } |
| 149 | + |
| 150 | + /// <summary> |
| 151 | + /// Adds Ocelot configuration by ready configuration object and writes JSON to the primary configuration file.<br/> |
| 152 | + /// Finally, adds JSON file as configuration provider. |
| 153 | + /// </summary> |
| 154 | + /// <remarks>Use optional arguments for injections and overridings.</remarks> |
| 155 | + /// <param name="builder">Configuration builder to extend.</param> |
| 156 | + /// <param name="fileConfiguration">File configuration to add as JSON provider.</param> |
| 157 | + /// <param name="primaryConfigFile">Primary config file.</param> |
| 158 | + /// <param name="optional">The 2nd argument of the AddJsonFile.</param> |
| 159 | + /// <param name="reloadOnChange">The 3rd argument of the AddJsonFile.</param> |
| 160 | + /// <returns>An <see cref="IConfigurationBuilder"/> object.</returns> |
| 161 | + public static IConfigurationBuilder AddOcelot(this IConfigurationBuilder builder, FileConfiguration fileConfiguration, |
| 162 | + string primaryConfigFile = null, bool? optional = null, bool? reloadOnChange = null) // optional injections |
| 163 | + { |
| 164 | + var json = JsonSerializer.Serialize(fileConfiguration, JsonSerializerOptionsFactory.WebWriteIndented); |
| 165 | + return AddOcelotJsonFile(builder, json, primaryConfigFile, optional, reloadOnChange); |
| 166 | + } |
168 | 167 |
|
169 | 168 | /// <summary>
|
170 | 169 | /// Adds Ocelot configuration by ready configuration object, environment and merge option, reading the required files from the current default folder.
|
|
0 commit comments