PiwigoDirectorySync/PiwigoDirectorySync/AppSettings.cs

20 lines
1007 B
C#
Raw Normal View History

using Microsoft.Extensions.Configuration;
namespace PiwigoDirectorySync;
internal static class AppSettings
{
public static readonly IReadOnlySet<string> SupportedExtensions = new HashSet<string> { "jpg", "jpeg", "png" };
public static IConfigurationRoot Config { get; } = new ConfigurationBuilder().SetBasePath(AppContext.BaseDirectory)
.AddJsonFile("appsettings.json", true)
.AddJsonFile(Path.Combine(Environment.CurrentDirectory, "appsettings.json"), true)
.AddJsonFile("/etc/PiwigoDirectorySync/appsettings.json", true)
.AddEnvironmentVariables()
.Build();
public static Settings Settings { get; } = Config.GetSection("settings").Get<Settings>() ?? throw new InvalidOperationException("Could not parse settings");
public static string ConnectionString =>
Config.GetConnectionString(Settings.DbProvider) ?? throw new InvalidOperationException($"Could not find connection string for provider {Settings.DbProvider}");
}