0

as per the code below, I am connecting to an azure app configuration service in program.cs. This is tested and I can use the config settings in the function app. But I'd also like to configure other services, such as a blob container client.

is it possible for me to access the app configuration values in ConfigureServices?

var host = new HostBuilder()
    .ConfigureAppConfiguration(builder =>
    {
        string uriString = "https://sixdg-appconfigservice-uks-reportingservice.azconfig.io";
        builder.AddAzureAppConfiguration(options => 
        {
            options.Connect(new Uri(uriString), new DefaultAzureCredential());
        });
    })
    .ConfigureServices(s =>
    {
        //configure services here using AppConfiguration
        Uri blobUri = new Uri(Environment.GetEnvironmentVariable("ReportBlobUri")); // use appconfig here instead of environmental variables
        BlobServiceClient blobServiceClient = new BlobServiceClient(blobUri, new DefaultAzureCredential());
        BlobContainerClient blobContainerClient = blobServiceClient.GetBlobContainerClient(Environment.GetEnvironmentVariable("ReportBlobContainer"));
        s.AddSingleton(blobContainerClient);
    })
    .ConfigureFunctionsWorkerDefaults()
    .Build();

host.Run();
Oliver
  • 87
  • 1
  • 10

1 Answers1

0

You may not have access to the configuration of the Function app at this point, but you can make another request to Azure App Configuration and get what you need. For example,

.ConfigureServices(services =>
{
    var configBuilder = new ConfigurationBuilder();
    configBuilder.AddAzureAppConfiguration(options =>
    {
        optiions.Connect(new Uri(uriString), new DefaultAzureCredential())
                .Select("ReportBlob*");
    });
    IConfiguration config = configBuilder.Build();
    string reportBlobUri = config["ReportBlobUri"];
    
    // Use what you get from Azure App Configuration to configure your other services.
})
Zhenlan Wang
  • 1,213
  • 8
  • 10