47 lines
1.6 KiB
C#
47 lines
1.6 KiB
C#
namespace BankSampahApp.Services;
|
|
|
|
/// <summary>
|
|
/// Implementation of centralized configuration service
|
|
/// </summary>
|
|
public class AppConfigurationService : IAppConfigurationService
|
|
{
|
|
private readonly IConfiguration _configuration;
|
|
private readonly CacheSettings _cacheSettings;
|
|
private readonly StatisticsSettings _statisticsSettings;
|
|
private readonly DevelopmentSettings _developmentSettings;
|
|
|
|
public AppConfigurationService(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
|
|
|
|
_cacheSettings = new CacheSettings();
|
|
_configuration.GetSection("Cache").Bind(_cacheSettings);
|
|
|
|
_statisticsSettings = new StatisticsSettings();
|
|
_configuration.GetSection("Statistics").Bind(_statisticsSettings);
|
|
|
|
_developmentSettings = new DevelopmentSettings();
|
|
_configuration.GetSection("Development").Bind(_developmentSettings);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public T GetValue<T>(string key, T defaultValue)
|
|
{
|
|
return _configuration.GetValue<T>(key) ?? defaultValue;
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public string ApplicationName => GetValue("Application:Name", "Bank Sampah Digital");
|
|
|
|
/// <inheritdoc/>
|
|
public bool ShowDetailedExceptions => _developmentSettings.DetailedExceptions;
|
|
|
|
/// <inheritdoc/>
|
|
public CacheSettings CacheSettings => _cacheSettings;
|
|
|
|
/// <inheritdoc/>
|
|
public StatisticsSettings StatisticsSettings => _statisticsSettings;
|
|
|
|
/// <inheritdoc/>
|
|
public DevelopmentSettings DevelopmentSettings => _developmentSettings;
|
|
} |