Skip to content

Configuration and FunctionsHostBuilderContext support

Brett Samblanet edited this page Aug 12, 2020 · 3 revisions

Version 1.1.0 of the Microsoft.Azure.Functions.Extensions package adds two new features to this class. This version of the package is currently in preview on nuget and supported in the following host versions:

  • Any Functions v2 host version greater than 2.0.14192.0
  • Any Functions v3 host version greater than 3.0.14191.0

Configuration support

IFunctionsConfigurationBuilder support is currently in preview on nuget and only supported in the following host versions:

  • Any Functions v2 host version greater than 2.0.14192.0
  • Any Functions v3 host version greater than 3.0.14191.0

This preview package adds a new override-able method on FunctionsStartup:

public virtual void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)

The IFunctionsConfigurationBuilder interface has one property:

IConfigurationBuilder ConfigurationBuilder { get; }

When overridden, the Azure Functions host will call into this method and provide an IConfigurationBuilder that can be used to register any ConfigurationProvider. This provider will then be used by the host to build the IConfiguration for use throughout the Job Host and your registered services.

Important

For Azure Function apps running in the Consumption or Premium plans, configuration values that are used in bindings cannot be modified with a custom configuration source. During startup, the host will check to see whether any properties have changed after calling into a FunctionsStartup class and if so the host will log an error and fail to start. This is because these plans require that the Functions Scale controller knows the proper settings to monitor for scale out, and if these values change, it can result in scaling errors.

FunctionHostBuilderContext support

FunctionsHostBuilderContext is a helpful class that can be accessed from either IFunctionsConfigurationBuilder or IFunctionsHostBuilder by calling the GetContext() extension method. For example:

public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
{
    FunctionsHostBuilderContext context = builder.GetContext();
    ...
}

This class provides details that can be useful while registering configuration sources or services. This context is very similar to Microsoft.Extensions.Hosting.HostBuilderContext, but has some values that are specific to Azure Function applications.

Samples

See the DependencyInjection sample project for how to register appsettings.json files: https://github.com/Azure/azure-functions-dotnet-extensions/blob/main/src/samples/DependencyInjection/Basic/SampleStartup.cs#L15-L24

Clone this wiki locally