Closed sachinvaid1604 closed 8 months ago
Sachin, fork Ocelot repo first to look into the Ocelot code!
After forking Ocelot you will figure out that AddJsonFile
method is a part of JsonConfigurationExtensions
class from Microsoft.Extensions.Configuration
namespace!
If you press F12 key multiple times, you will get to this Microsoft ASP.NET implementation:
/// <summary>
/// Adds a JSON configuration source to <paramref name="builder"/>.
/// </summary>
/// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param>
/// <param name="provider">The <see cref="IFileProvider"/> to use to access the file.</param>
/// <param name="path">Path relative to the base path stored in
/// <see cref="IConfigurationBuilder.Properties"/> of <paramref name="builder"/>.</param>
/// <param name="optional">Whether the file is optional.</param>
/// <param name="reloadOnChange">Whether the configuration should be reloaded if the file changes.</param>
/// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
public static IConfigurationBuilder AddJsonFile(this IConfigurationBuilder builder, IFileProvider? provider, string path, bool optional, bool reloadOnChange)
{
ThrowHelper.ThrowIfNull(builder);
if (string.IsNullOrEmpty(path))
{
throw new ArgumentException(SR.Error_InvalidFilePath, nameof(path));
}
return builder.AddJsonFile(s =>
{
s.FileProvider = provider;
s.Path = path;
s.Optional = optional;
s.ReloadOnChange = reloadOnChange;
s.ResolveFileProvider();
});
}
I have no idea how inner MS implementation merges config JSON.
If you call
.AddJsonFile("student.ocelot.Development.json", false, true)
.AddJsonFile("teacher.ocelot.Development.json", false, true)
and they describe the same routes, seems the second file will overwrite the routes from the first one. Microsoft classes don't merge!
Hi, Can you please provide a working code that can read multiple route configurations for each microservice and can run both. In my case, I can only access the last added route configuration.
Here is my program.cs file
Originally posted by @sachinvaid1604 in https://github.com/ThreeMammals/Ocelot/issues/1186#issuecomment-1859061387