I have the following but in order to use AddAzureKeyVault I need to know the key vault name which is set in configuration. Is it possible to read in this value in one go or do I need to build it twice?
private static IConfigurationRoot GetIConfigurationRoot()
{
var root = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false)
//.AddAzureKeyVault($"https://{keyVaultName}.vault.azure.net")
.AddEnvironmentVariables()
.Build();
return root;
}
Not sure why do you add your configuration like that, but it is possible in with
ConfigurationManagerfor example :Or
ConfigurationManagerimplements bothIConfigurationManagerandIConfigurationRoot, so it should work in your case.Not sure what kind of host are you building, but using the first example is always good option.
When you build your
IConfigurationRootI don't see a way to add more configuration sources.NOTE This is also valid:
I used
GetConnectionStringjust for sake of example, you can get your configuration from every section inappsettings.json.