namespace BpsRwApp.Services;
///
/// Implementation of centralized configuration service
///
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);
}
///
public T GetValue(string key, T defaultValue)
{
return _configuration.GetValue(key) ?? defaultValue;
}
///
public string ApplicationName => GetValue("Application:Name", "Bank Sampah Digital");
///
public bool ShowDetailedExceptions => _developmentSettings.DetailedExceptions;
///
public CacheSettings CacheSettings => _cacheSettings;
///
public StatisticsSettings StatisticsSettings => _statisticsSettings;
///
public DevelopmentSettings DevelopmentSettings => _developmentSettings;
}