/// <summary> /// Initializes config locations and setup /// </summary> private void Initialize() { var parentMask = pathMask; var searchPath = CurrentPath; var configFiles = new List <string>(); // Find RootPath if (File.Exists($@"{CurrentPath.AddLast(@"\")}{FileNames.AppSettingsJson}")) { RootPath = CurrentPath; } else { for (var count = 0; count < parentLevels; count++) { searchPath = Path.GetFullPath(Path.Combine(CurrentPath, parentMask)); if (File.Exists($@"{searchPath.AddLast(@"\")}{FileNames.AppSettingsJson}")) { RootPath = searchPath; break; } parentMask += pathMask; } } // Add appsettings.json if (File.Exists($@"{RootPath.AddLast(@"\")}{FileNames.AppSettingsJson}")) { configFiles.Add($@"{RootPath.AddLast(@"\")}{FileNames.AppSettingsJson}"); } // Add appsettings.{environment}.json if (File.Exists($@"{RootPath.AddLast(@"\")}{string.Format(FileNames.AppSettingsEnvironmentJson, CurrentEnvironment)}")) { configFiles.Add($@"{RootPath.AddLast(@"\")}{string.Format(FileNames.AppSettingsEnvironmentJson, CurrentEnvironment)}"); } // Add App_Data\AppSettings.json if (File.Exists($@"{AppDataFolder.AddLast(@"\")}{FileNames.AppSettingsJson}")) { configFiles.Add($@"{AppDataFolder.AddLast(@"\")}{FileNames.AppSettingsJson}"); } // Add App_Data\ConnectionStrings.json if (File.Exists($@"{AppDataFolder.AddLast(@"\")}{FileNames.ConnectionStringsJson}")) { configFiles.Add($@"{AppDataFolder.AddLast(@"\")}{FileNames.ConnectionStringsJson}"); } // Load Load(configFiles); }