Added overload of the IConfigurationBuilder.AddOcelot extension-method that accepts a specific folder (#476)

This commit is contained in:
Edwin van Wijk
2018-07-19 18:49:47 +02:00
committed by Tom Pallister
parent 5c940acf0e
commit 12ef3bc00f
2 changed files with 41 additions and 9 deletions

View File

@ -29,12 +29,17 @@ namespace Ocelot.DependencyInjection
}
public static IConfigurationBuilder AddOcelot(this IConfigurationBuilder builder)
{
return builder.AddOcelot(".");
}
public static IConfigurationBuilder AddOcelot(this IConfigurationBuilder builder, string folder)
{
const string pattern = "(?i)ocelot\\.([a-zA-Z0-9]*)(\\.json)$";
var reg = new Regex(pattern);
var files = Directory.GetFiles(".")
var files = Directory.GetFiles(folder)
.Where(path => reg.IsMatch(path))
.ToList();
@ -43,7 +48,7 @@ namespace Ocelot.DependencyInjection
foreach (var file in files)
{
// windows and unix sigh...
if(files.Count > 1 && (file == "./ocelot.json" || file == ".\\ocelot.json"))
if(files.Count > 1 && (Path.GetFileName(file) == "ocelot.json"))
{
continue;
}
@ -53,7 +58,7 @@ namespace Ocelot.DependencyInjection
var config = JsonConvert.DeserializeObject<FileConfiguration>(lines);
// windows and unix sigh...
if (file == "./ocelot.global.json" || file == ".\\ocelot.global.json")
if (Path.GetFileName(file) == "ocelot.global.json")
{
fileConfiguration.GlobalConfiguration = config.GlobalConfiguration;
}