77 lines
2.3 KiB
C#
77 lines
2.3 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace FsTool.Helpers
|
|
{
|
|
/// <summary>
|
|
/// Represents the root configuration settings for the application, including API and credentials.
|
|
/// </summary>
|
|
public class AppSettings
|
|
{
|
|
/// <summary>
|
|
/// Gets the API-related settings.
|
|
/// </summary>
|
|
public ApiSettings Api { get; init; } = new();
|
|
|
|
/// <summary>
|
|
/// Gets the credentials settings for authentication.
|
|
/// </summary>
|
|
public CredentialsSettings Credentials { get; init; } = new();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Contains settings related to the API endpoints.
|
|
/// </summary>
|
|
public class ApiSettings
|
|
{
|
|
/// <summary>
|
|
/// Gets the base URL for the API, without the /api path segment.
|
|
/// </summary>
|
|
public string BaseUrl { get; init; } = "https://beta.foodsharing.de";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Contains credentials and authentication settings.
|
|
/// </summary>
|
|
public class CredentialsSettings
|
|
{
|
|
/// <summary>
|
|
/// Gets the email address used for login.
|
|
/// </summary>
|
|
public string Email { get; init; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// Gets the password used for login.
|
|
/// </summary>
|
|
public string Password { get; init; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// Gets a value indicating whether two-factor authentication is enabled.
|
|
/// </summary>
|
|
public bool TwoFactorEnabled { get; init; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Provides access to the current application settings loaded from configuration.
|
|
/// </summary>
|
|
public static class SettingsProvider
|
|
{
|
|
private static AppSettings? _current;
|
|
|
|
/// <summary>
|
|
/// Gets the current application settings instance.
|
|
/// </summary>
|
|
public static AppSettings Current => _current ??= Load();
|
|
|
|
private static AppSettings Load()
|
|
{
|
|
var configuration = new ConfigurationBuilder()
|
|
.SetBasePath(AppContext.BaseDirectory)
|
|
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
|
.Build();
|
|
|
|
var settings = new AppSettings();
|
|
configuration.Bind(settings);
|
|
return settings;
|
|
}
|
|
}
|
|
} |