Base class for bootstrapping applications. The library will be used in whole RaGae namespace (if necessary!).
To install BootstrapLib it is possible to download library [zip | gzip] or install it via nuget.
PM> Install-Package RaGae.Bootstrap
After adding/installing the BootstrapLib in a project it can be used to bootstrap the application.
Loader.LoadConfig(file, optional, reload)
Loader.LoadConfigSection(file, section, optional, reload)
To bind config from file to a provided class.
Filename for specific *.json file to load.
T config = Loader.LoadConfig<T>("Filename", "...", "...");
T config = Loader.LoadConfigSection<T>("Filename", "..." "...", "...");
This parameter defines in which section in the json file the configuration can be found. The parameter is not necessary and can be omitted.
T config = Loader.LoadConfigSection<T>("...", "DemoConfig" "...", "...");
This parameter defines if the configuration is optional (can be loaded but must not be loaded!). The parameter is not necessary and can be omitted.
T config = Loader.LoadConfig<T>("Filename", false/true, "...");
T config = Loader.LoadConfigSection<T>("...", "...", false/true, "...");
This parameter defines if the configuration should be reloaded at runtime if parameters are changed. The parameter is not necessary and can be omitted.
T config = Loader.LoadConfig<T>("Filename", "...", false/true);
T config = Loader.LoadConfigSection<T>("...", "...", "...", false/true);
Information how to handle a project with BootstrapLib can be found in Wiki.
{
"DemoConfig": {
"Value": 1,
"Array": [
{ "Value": 1 }
]
}
}
{
"Value": 1,
"Array": [
{ "Value": 1 }
]
}
using System;
using RaGae.BootstrapLib.Loader;
namespace Project
{
public LoadConfig()
{
try
{
// Appsettings with no configuration section
DemoConfig demo = Loader.LoadConfig<DemoConfig>("appsettings.nosection.json", false, false);
// Appsettings with configuration section
DemoConfig demo = Loader.LoadConfigSection<DemoConfig>("appsettings.section.json", nameof(DemoConfig), false, false);
string demoValue = demo.Value;
string demoArrayValue = demo.ElementAt(0).Value;
}
catch(Exception ex)
{
// ...
}
}
}
namespace Project
{
public enum ErrorCode
{
OK,
ERROR,
TEST
}
public class DemoConfig
{
private IEnumerable<DemoArrayConfig> array;
private int value;
public int Value
{
get => this.value;
set
{
if (value < 1)
throw new ArgumentException(nameof(DemoConfig));
this.value = value;
}
}
public IEnumerable<DemoArrayConfig> Array
{
get => this.array;
set
{
value.ToList().ForEach(e =>
{
if (e.Error != ErrorCode.OK)
throw new ArgumentException(nameof(DemoArrayConfig));
});
this.array = value;
}
}
}
public class DemoArrayConfig
{
private int value;
public int Value
{
get => this.value;
set
{
this.Error = ErrorCode.OK;
if (value < 1)
this.Error = ErrorCode.ERROR;
this.value = value;
}
}
public ErrorCode Error { get; private set; }
}
}
R. GÄCHTER