I moved from values from loca.settings.json to Azure Key Vault. I added the Azure Key Vault as a Connected Service.
I have a problem with binding sections.
I have a class
public class AzureStorageBlobSettings
{
public string AccountName { get; set; }
public string ConnectionString { get; set; }
}
In Startup class, I bind Azure Key Vaults values to AzureStorageBlobSettings class.
builder.Services.Configure<AzureStorageBlobSettings>(_configuration.GetSection("AzureStorageBlobSettings"));
In my Azure Function, I inject AzureStorageBlobSettings using the Options pattern.
private readonly AzureStorageBlobSettings _azureStorageBlobSettings;
readonly IConfiguration _configuration;
public UploadDocumentFunction(AzureStorageBlobOptionsTokenGenerator azureStorageBlobOptionsTokenGenerator,
IOptions<AzureStorageBlobSettings> azureStorageBlobSettings,
IConfiguration configuration)
{
_azureStorageBlobOptionsTokenGenerator = azureStorageBlobOptionsTokenGenerator;
_configuration = configuration;
_azureStorageBlobSettings = azureStorageBlobSettings.Value;
}
In Azure Key Vault I added the following secrets:
I added two dashes so AzureStorageBlobSettings should be a section, but settings aren't being bound and _azureStorageBlobSettings values are null.
Connection to Azure Key Vault works fine because when I get only one value from IConfiguration it works, like
_configuration["AzureStorageBlobSettings:AccountName"]
The question is what I am doing wrong with the binding section from Azure Key Vault?