You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Tutorial: Use dynamic configuration in an Azure Functions app
18
18
19
-
The App Configuration .NET configuration provider supports caching and refreshing configuration dynamically driven by application activity. This tutorial shows how you can implement dynamic configuration updates in your code. It builds on the Azure Functions app introduced in the quickstarts. Before you continue, finish [Create an Azure functions app with Azure App Configuration](./quickstart-azure-functions-csharp.md) first.
19
+
This tutorial shows how you can enable dynamic configuration updates in your Azure Functions app. It builds upon the Azure Functions app introduced in the quickstarts. Before you continue, finish [Create an Azure functions app with Azure App Configuration](./quickstart-azure-functions-csharp.md) first.
20
20
21
21
In this tutorial, you learn how to:
22
22
23
23
> [!div class="checklist"]
24
-
> * Set up your Azure Functions app to update its configuration in response to changes in an App Configuration store.
25
-
> * Inject the latest configuration to your Azure Functions calls.
24
+
> * Set up dynamic configuration refresh for your Azure Functions app.
25
+
> * Enable automatic configuration refresh using App Configuraion middleware.
26
+
> * Use the latest configuration in Function calls when changes occur in your App Configuration store.
26
27
27
28
## Prerequisites
28
29
29
-
- Azure subscription - [create one for free](https://azure.microsoft.com/free/)
30
-
-[Visual Studio](https://visualstudio.microsoft.com/vs) with the **Azure development** workload
31
-
-[Azure Functions tools](../azure-functions/functions-develop-vs.md), if it's not installed already with Visual Studio.
32
30
- Finish quickstart [Create an Azure functions app with Azure App Configuration](./quickstart-azure-functions-csharp.md)
33
31
34
32
## Reload data from App Configuration
35
33
36
-
Azure Functions support running [in-process](../azure-functions/functions-dotnet-class-library.md) or [isolated-process](../azure-functions/dotnet-isolated-process-guide.md). The main difference in App Configuration usage between the two modes is how the configuration is refreshed. In the in-process mode, you must make a call in each function to refresh the configuration. In the isolated-process mode, there is support for middleware. The App Configuration middleware, `Microsoft.Azure.AppConfiguration.Functions.Worker`, enables the call to refresh configuration automatically before each function is executed.
34
+
The Azure App Configuration .NET provider supports caching and dynamic refresh of configuration settings based on application activity. In this section, you configure the provider to refresh settings dynamically and enable automatic configuration refresh using the App Configuration middleware, `Microsoft.Azure.AppConfiguration.Functions.Worker`, each time a function executes.
37
35
38
-
1. Update the code that connects to App Configuration and add the data refreshing conditions.
39
-
40
-
### [In-process](#tab/in-process)
41
-
42
-
Open *Startup.cs*, and update the `ConfigureAppConfiguration` method.
36
+
> [!NOTE]
37
+
> Azure App Configuration can be used with Azure Functions in either the [isolated worker model](../azure-functions/dotnet-isolated-process-guide.md) or the [in-process model](../azure-functions/functions-dotnet-class-library.md). This tutorial uses the isolated worker model as an example. You can find complete code examples for both models in the [Azure App Configuration GitHub repository](https://github.com/Azure/AppConfiguration/tree/main/examples/DotNetCore/AzureFunctions).
43
38
39
+
1. Open the *Program.cs* file and update the call to `AddAzureAppConfiguration` to include the `ConfigureRefresh` method. This method configures the conditions for refreshing configuration settings, including specifying the keys to monitor and the interval between refresh checks.
44
40
41
+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
thrownewInvalidOperationException("The environment variable 'AZURE_APPCONFIG_CONNECTION_STRING' is not set or is empty.");
69
+
options.Connect(connectionString)
70
+
// Load all keys that start with `TestApp:` and have no label
71
+
.Select("TestApp:*")
72
+
// Reload configuration if any selected key-values have changed.
73
+
// Use the default refresh interval of 30 seconds. It can be overridden via AzureAppConfigurationRefreshOptions.SetRefreshInterval.
74
+
.ConfigureRefresh(refreshOptions=>
75
+
{
76
+
refreshOptions.RegisterAll();
77
+
});
78
+
});
85
79
```
86
80
---
87
81
88
-
The `ConfigureRefresh` methodregistersasettingtobecheckedfor changes whenever a refresh is triggered within the application. The `refreshAll` parameter instructs the App Configuration provider to reload the entire configuration whenever a change is detected in the registered setting.
89
-
90
-
All settings registered for refresh have a default cache expiration of 30 seconds before a new refresh is attempted. It can be updated by calling the `AzureAppConfigurationRefreshOptions.SetCacheExpiration` method.
> When you are updating multiple key-values in App Configuration, you normally don't want your application to reload configuration before all changes are made. You can register a *sentinel key* and update it only when all other configuration changes are completed. This helps to ensure the consistency of configuration in your application.
94
-
>
95
-
> You may also do the following to minimize the risk of inconsistencies:
96
-
>
97
-
> * Design your application to be tolerable for transient configuration inconsistency
98
-
> * Warm-up your application before bringing it online (servingrequests)
@@ -209,35 +160,30 @@ Azure Functions support running [in-process](../azure-functions/functions-dotnet
209
160
210
161

211
162
212
-
5. Signintothe [Azureportal](https://portal.azure.com). Select **All resources**, and select the App Configuration store that you created in the quickstart.
0 commit comments