public class DataAccessOptions
{
public ConfigOptions Config { get; set; }
public class ConfigOptions
{
public DataAccessConnectionString ConnectionStrings { get; set; }
}
public class DataAccessConnectionString
{
public string UserDb { get; set; }
}
}
As far as I can tell this does not work.
This does not work as well.
var options = new DataAccessOptions();hostContext.Configuration.GetSection("Config").Bind(options);
this does not work
hostContext.Configuration.GetSection("Config");
And that kind of is not a way. Imagine i got N of stuff in secret. Then I have to initiate class and fill in all of that stuff manually like:
var options = new DataAccessOptions {
Config = new ConfigOptions {
ConnectionStrings = new DataAccessConnectionString {
UserDb = hostContext.Configuration.GetValue<string>("Config:ConnectionStrings:UserDb");
// and N other stuff in here
}
}
}
Is there a way to bind secrets to a class and not to do that get one at the time.
On Azure when you define secret "Config:ConnectionStrings:UserDb" syntax is recognised like section on you can unpack in one line of code.
I am sorry. So stupid class is wrong. Config is extra property that is not needed. And hostContext.Configuration.GetSection("Config"); this Osx debugger is now showing value ....
If i have secret called Config and in it plain:
Where
DataAccessOptions
is a class with:As far as I can tell this does not work.
This does not work as well.
var options = new DataAccessOptions();
hostContext.Configuration.GetSection("Config").Bind(options);
this does not work
hostContext.Configuration.GetSection("Config");
Only thing that works is:
hostContext.Configuration.GetValue<string>("Config:ConnectionStrings:UserDb");
And that kind of is not a way. Imagine i got N of stuff in secret. Then I have to initiate class and fill in all of that stuff manually like:
Is there a way to bind secrets to a class and not to do that get one at the time.
On Azure when you define secret "Config:ConnectionStrings:UserDb" syntax is recognised like section on you can unpack in one line of code.