Move CLI project into subfolder
This commit is contained in:
101
Cli/Helper/Settings.cs
Normal file
101
Cli/Helper/Settings.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace FsToolbox.Cli.Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the root configuration settings for the application, including API and credentials.
|
||||
/// </summary>
|
||||
public class AppSettings
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
/// <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();
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains settings related to the API endpoints.
|
||||
/// </summary>
|
||||
public class ApiSettings
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the base URL for the API, without the /api path segment.
|
||||
/// </summary>
|
||||
public string BaseUrl { get; init; } = "https://beta.foodsharing.de";
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains credentials and authentication settings.
|
||||
/// </summary>
|
||||
public class CredentialsSettings
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
/// <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; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides access to the current application settings loaded from configuration.
|
||||
/// </summary>
|
||||
public static class SettingsProvider
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private static AppSettings? _current;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current application settings instance.
|
||||
/// </summary>
|
||||
public static AppSettings Current => _current ??= Load();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Method Load
|
||||
|
||||
private static AppSettings Load()
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(AppContext.BaseDirectory)
|
||||
.AddJsonFile("appsettings.json", false, true)
|
||||
.Build();
|
||||
|
||||
var settings = new AppSettings();
|
||||
configuration.Bind(settings);
|
||||
return settings;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user