This repository has been archived on 2024-03-29. You can view files and clone it, but cannot push or open issues or pull requests.
FreeSR/FreeSR.Shared/Configuration/ConfigurationManager.cs

26 lines
760 B
C#
Raw Permalink Normal View History

2024-01-27 13:06:07 +00:00
namespace FreeSR.Shared.Configuration
{
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Primitives;
public sealed class ConfigurationManager<T> : Singleton<ConfigurationManager<T>> where T : class
{
public IConfiguration Config { get; private set; }
public T Model { get; private set; }
public void Initialize(string path)
{
var builder = new ConfigurationBuilder()
.AddJsonFile(path, false, true)
.AddEnvironmentVariables();
Config = builder.Build();
Model = Config.Get<T>();
ChangeToken.OnChange(
Config.GetReloadToken,
() => Model = Config.Get<T>());
}
}
}