mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 08:18:16 +08:00
Added overload of the IConfigurationBuilder.AddOcelot extension-method that accepts a specific folder (#476)
This commit is contained in:

committed by
Tom Pallister

parent
5c940acf0e
commit
12ef3bc00f
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user