From .NET 6 to .NET 8+,my migration experience:Using Azure AppConfiguration in Azure Functions on .NET8+ isolated
Introduction
I recently migrated many Azure Functions . These functions were running on .NET 6 in-process, and I migrated them to .NET 8 isolated. I had to make some breaking changes regarding configuration and especially Azure AppConfiguration settings. In this post, I will show you the necessary modifications regarding this.
How it was with .NET 6 in-process
With .NET 6 in-process, the configuration needed more work. The configuration was accessible from IConfigurationRoot interface and needed to get updated manually with the IConfigurationRefresher interface. They both needed to be registered in the DI as follows in the Startup.cs file:
The code above shows how to setup Azure AppConfiguration + how configuration is getting configured for refresh.
Next step is to update yours functions in your app, for example an HttpTrigger. The following code shows how we used to access the configuration from IConfiguration and how we refresh it manually:
As you can see, we needed to inject IConfigurationRoot and IConfigurationRefresher and invoke the TryRefreshAsync method to get the refreshed configuration.
I’m now glad to say this is not needed and it become much easier with .NET isolated.
Migrating to .NET 8+ isolated
First off, you’ll need to download the following packages while migrating:
- Microsoft.Extensions.Configuration.AzureAppConfiguration (Same package as .NET 6 in-process).
- Microsoft.Azure.AppConfiguration.Functions.Worker
Then rewrite your code as follows: (Note that I also took the time to replace the Startup.cs file by the Program.cs file with the Top-level program feature)
As you can see the file is lighter but also the following assignation is not needed anymore: ConfigurationRefresher = options.GetRefresher();.
Why ? There is no needed anymore to use the IConfigurationRefresher interface to refresh manually the configuration in your code before accessing it. Only the the ConfigureRefresh method remains, the later is still needed to tell the app that the config must be refreshed from Azure AppConfiguration. Also, the SetCacheExpiration method is getting deprecated, you will have to replace it with the SetRefreshInterval method, its parameter remain unchanged.
In consequence you can remove the registration of IConfigurationRoot and IConfigurationRefresher and replace them by the following method: AddAzureAppConfiguration.
Keep in mind you need to add the AppConfiguration middleware (UseAzureAppConfiguration) within the ConfigureFunctionsWebApplication (IHostbuilder). The ConfigureFunctionsWebApplication host builder is the ASP.NET Core Integration and you can learn how to set it up here: https://anthonygiretti.com/2024/11/04/asp-net-core-using-the-asp-net-core-integration-on-azure-functions/.
Now If we go on the previous HttpTrigger, the latter would look like this (it’s including the HttpTriggers specific changes):
You can use straight the IConfiguration interface (automatically registered in the DI in place of IConfigurationRoot). The latter will be automatically updated when the configuration is refreshed. No more IConfigurationRefresher and TryRefreshAsync in your code!
Hope you enjoyed this tutorial 🙂