dotnet add package wk.SettingsGenerator
- Add configuration into
appsettings.json
{
"Alfresco": {
"Url": "http://localhost:8080",
"User": "admin",
"Password": "admin"
},
"Database": {
"ConnectionString": "Host=localhost"
}
}
- Generate settings class
[AppSettings(FileName = "appsettings.json")]
public partial class AppSettings { }
- Load settings
public void ConfigureServices(IServiceCollection services) {
var settings = Configuration.Get<AppSettings>();
Console.WriteLine(settings.Alfresco.Url);
Console.WriteLine(settings.Database.ConnectionString);
...
}