I am upgrading my function from .NET Core 3.1 up to .NET 7 Isolated
My Function App inherits from a base class which does all my setup that is relevant to all function app. This works perfectly
However, in .NET 7 Isolated, it appears as though function startup is not supported/recommended?
I can create a function initializer class which I can then call to setup my services, this is fine
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults((IFunctionsWorkerApplicationBuilder builder) =>
{
})
.ConfigureServices((context, s) =>
{
var initializer = new FunctionAppInitializer(s);
initializer.Run();
})
.Build();
host.Run();
However, I have a problem with configuration as this is not available.
How can I run the method below?
public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
{
var kvEndpoint =
Environment.GetEnvironmentVariable("ASPNETCORE_HOSTINGSTARTUP__KEYVAULT__CONFIGURATIONVAULT");
var environmentName =
Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
builder.ConfigurationBuilder
.AddAzureKeyVault(new Uri(kvEndpoint!), new DefaultAzureCredential())
.SetBasePath(Environment.CurrentDirectory)
.AddJsonFile("local.settings.json", optional: true)
.AddJsonFile($"local.settings.{environmentName}.json", optional: true)
.AddEnvironmentVariables()
.Build();
}
This is overriding FunctionStartup.ConfigureAppConfiguration which gives me access to the builder.
With the new method, although I can get to builder inside ConfigureFunctionsWorkerDefaults, the builder object does not have ConfigurationBuilder
Paul
You can use
ConfigureHostConfiguration
method