MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.28k stars 21.47k forks source link

Account IConfiguration inside Configure method #99087

Open dulfe opened 2 years ago

dulfe commented 2 years ago

This page shows how to use Dependency injection in Azure Functions as well as how to customize logging, but it does not show how to get access to the configuration (IConfiguration) in the Configure method.

That is needed to configure Azure clients.

I know we can get the values from the "environment," but it would be better to use a standard way.

For example:

public class Startup : FunctionsStartup
{
    public override void Configure(IFunctionsHostBuilder builder)
    {
        // IConfiguration config = ????

        builder.Services.AddSingleton<IMyService, Service>(s => {
            return new Service(config.GetValue<string>("mysetting"));
        });

        builder.Services.AddAzureClients(azureBuilder =>
        {
            azureBuilder.AddServiceBusClient(config.GetConnectionStringOrSetting("QueueConnectionString"));
        });

    }
}

Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

mikeurnun commented 2 years ago

Thank you for your feedback! We have assigned this issue to the author to review further and take the next course of action.