This is a small Helper for consuming strong typed json config files from a path.
Available via nuget
- Fix: Environment variable gets ignored
- First Release
//TestConfig.cs
public class TestConfig
{
public string TestValue1 { get; set; }
}
//TestConfig.json
{
"TestValue1": "Conf Test Value 2"
}
var conf = Loader.LoadFile<TestConfig>("TestConf.json");
conf.TestValue1; //Conf Test Value 2
It is possible to specify that parts of your config come from other files
//TestConfig.cs
public class TestConfig
{
public string TestValue1 { get; set; }
[FileSource("SubFile.json")]
public TestSubFileConfig subConfig { get; set; }
}
TestConfig.json
stays the same
//SubFile.json
{
"SubFileValue": "SubFileValue Test value"
}
var conf = Loader.LoadFile<TestConfig>("TestConf.json");
conf.TestValue1; //Conf Test Value 2
conf.subConfig.SubFileValue; //SubFileValue Test value
You can set the config root
Aniel.SimpleConf.Loader.ConfigRoot = "<path to folder with config files>";
//Make sure you set useConfigRoot
Loader.LoadFile<TestConfig>("TestConf.json", useConfigRoot: true);
If you set the environment variable CONFIG_ROOT_PATH
you can overwrite the config root.
If you want to change the name of the environment variable you can use:
Aniel.SimpleConf.SimpleConfConstants.EnvironmentConfigPathName = "<yor environment variable name>";