I've been playing around a bit with Azure App Configuration.
Here's an example configruation:
var environmentVariable = Environment.GetEnvironmentVariable("AppConfigurationConnectionString");
var config =
new ConfigurationBuilder()
.AddAzureAppConfiguration(options =>
{
options.Connect(environmentVariable)
.ConfigureKeyVault(kv =>
{
kv.SetCredential(new DefaultAzureCredential());
});
})
.Build();
services.AddSingleton<IConfiguration>(config);
Following this, I can inject an IConfiguration
instance into my services and use _config["settingName"]
to access config settings. This all works well and is really quite nice.
One thing that I don't know how to do is to map groups of related settings to a strongly typed object (that is, without having to do it all manually, which I could do, but... hoping there's a better way).
In conventional ASP.NET core configuration, I can group related settings settings as follows (i.e. in appsettings.json
)
{
"test": {
"key1": "value1",
"key2": "value2"
}
}
using the IOptions pattern as follows:
services.Configure<Test>(config.GetSection("test"));
which allows me to inject a strongly-typed IOptions<Test>
instance into my classes. IMO this is a bit nicer than a big flat indexer, where I use _config["key1"]
to get config settings.
Is there an approach for Azure App Configruation to allow me to automatically configure strongly-typed config objects that can be injected into my classes?
TIA