### Selector Configuration Example Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/architecture.md Demonstrates how to configure selectors to specify which key-values should be loaded from Azure App Configuration. ```plaintext User Code | Select("Settings:*") ---- Select("Features:*") ----+---> KeyValueSelector[] SelectSnapshot("prod") ---- | Passed to AzureAppConfigurationOptions | Used during Load() to query App Configuration ``` -------------------------------- ### Basic ConfigurationBuilder Setup Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/configuration.md Use this pattern to initialize the configuration builder and add Azure App Configuration with a connection string. ```csharp var builder = new ConfigurationBuilder(); builder.AddAzureAppConfiguration("connection_string"); var config = builder.Build(); ``` -------------------------------- ### Mapper Configuration Example Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/architecture.md Shows how to define custom transformations (mappers) for configuration settings using C# code. ```csharp options.Map(async (setting) => { // Can decrypt, validate, or modify settings return setting; }); ``` -------------------------------- ### Configure Startup Options Callback Example Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/startup-configuration.md Provides a callback to configure startup options, specifically setting the timeout to 120 seconds. ```csharp options.ConfigureStartupOptions(startup => { startup.Timeout = TimeSpan.FromSeconds(120); }); ``` -------------------------------- ### Basic Azure App Configuration Refresh Setup Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/aspnet-core-middleware.md Illustrates the fundamental setup for enabling automatic refresh of configuration from Azure App Configuration. This snippet registers all settings and sets a default refresh interval. ```csharp var configBuilder = new ConfigurationBuilder() .AddJsonFile("appsettings.json"); configBuilder.AddAzureAppConfiguration(options => { options.Connect(connectionString) .Select("Settings:*") .ConfigureRefresh(refresh => { refresh.RegisterAll() .SetRefreshInterval(TimeSpan.FromSeconds(30)); }); }); ``` -------------------------------- ### Configure Startup Timeout Example Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/startup-configuration.md Sets a custom timeout of 60 seconds for loading configuration data from Azure App Configuration during application startup. ```csharp var configBuilder = new ConfigurationBuilder(); configBuilder.AddAzureAppConfiguration(options => { options.Connect("connection_string") .Select("Settings:*") .ConfigureStartupOptions(startup => { startup.Timeout = TimeSpan.FromSeconds(60); }); }); var config = configBuilder.Build(); // All selected keys must be loaded within 60 seconds ``` -------------------------------- ### Selective Key Loading by Environment Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/README.md Dynamically select configuration keys based on the current environment. This example loads 'Dev:*' keys in development and 'Prod:*' keys in other environments. ```csharp options.Select(env.IsDevelopment() ? "Dev:*" : "Prod:*"); ``` -------------------------------- ### Using IConfigurationRefresherProvider in Application Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/configuration.md Inject and use IConfigurationRefresherProvider to manually trigger configuration refreshes. This example iterates through all available refreshers and attempts to refresh their configurations. ```csharp public MyService(IConfigurationRefresherProvider refresherProvider) { _refresherProvider = refresherProvider; } public async Task RefreshConfiguration() { foreach (var refresher in _refresherProvider.Refreshers) { await refresher.TryRefreshAsync(); } } ``` -------------------------------- ### Dependency Graph for Configuration Refresher Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/architecture.md Shows the dependency graph starting from IConfiguration, leading to IConfigurationRefresherProvider and its associated refreshers. ```plaintext IConfiguration (from built configuration) | IConfigurationRefresherProvider (injected service) | +-- Refreshers { IConfigurationRefresher[] } | +-- RefreshAsync() +-- TryRefreshAsync() +-- ProcessPushNotification() ``` -------------------------------- ### ConfigurationBuilder with Refresh Registration Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/configuration.md Register keys for automatic refresh and configure the refresh interval. This example sets up refresh for 'Settings:Version' and refreshes all settings when it changes. ```csharp builder.AddAzureAppConfiguration(options => { options.Connect("connection_string") .Select("Settings:*") .ConfigureRefresh(refresh => { refresh.Register("Settings:Version", refreshAll: true) .SetRefreshInterval(TimeSpan.FromSeconds(30)); }); }); ``` -------------------------------- ### Initialization Data Flow Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/architecture.md Outlines the sequence of events during the initialization of the Azure App Configuration provider when an application starts. ```plaintext 1. Application calls AddAzureAppConfiguration() | 2. AzureAppConfigurationSource is created | 3. When IConfigurationRoot is built: - Load() is called on the provider - Connects to Azure App Configuration service - Queries keys based on selectors (Select/SelectSnapshot) - Applies mappers and adapters - Populates in-memory Key-Value store - Stores refresher instance for later use | 4. Configuration is ready for use | 5. AddAzureAppConfiguration(IServiceCollection) registers - IConfigurationRefresherProvider service - Allows dependency injection of refresher ``` -------------------------------- ### Configure ASP.NET Core (.NET 6+) App with Azure App Configuration Middleware Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/aspnet-core-middleware.md Shows the setup for Azure App Configuration middleware in a .NET 6+ application using the `WebApplication.CreateBuilder` pattern. It includes connecting to App Configuration, selecting settings, and configuring refresh. ```csharp var builder = WebApplication.CreateBuilder(args); // Configure App Configuration with refresh var configBuilder = new ConfigurationBuilder(); configBuilder.AddAzureAppConfiguration(options => { options.Connect(builder.Configuration["AppConfig:ConnectionString"]) .Select("Settings:*") .ConfigureRefresh(refresh => { refresh.Register("Settings:Version", refreshAll: true) .SetRefreshInterval(TimeSpan.FromSeconds(30)); }); }); builder.Configuration.AddConfiguration(configBuilder.Build()); // Add services builder.Services.AddAzureAppConfiguration(); builder.Services.AddControllers(); var app = builder.Build(); // Add middleware app.UseAzureAppConfiguration(); app.UseRouting(); app.MapControllers(); app.Run(); ``` -------------------------------- ### Selective Azure App Configuration Refresh Setup Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/aspnet-core-middleware.md Demonstrates how to configure selective refresh for specific configuration keys from Azure App Configuration. This allows fine-grained control over which settings trigger a refresh. ```csharp configBuilder.AddAzureAppConfiguration(options => { options.Connect(connectionString) .Select("AppSettings:*") .Select("Features:*") .ConfigureRefresh(refresh => { refresh.Register("Features:Sentinel", refreshAll: true) .Register("AppSettings:Version") .SetRefreshInterval(TimeSpan.FromSeconds(30)); }); }); ``` -------------------------------- ### Staged Rollout with Feature Flags Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/README.md Configure feature flags to enable staged rollouts. This example selects feature flags based on the environment, allowing different features to be enabled for different environments. ```csharp options.UseFeatureFlags(ff => { ff.Select("Features:*", env.EnvironmentName); }); ``` -------------------------------- ### ConfigurationBuilder with Feature Flags and Key Vault Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/configuration.md Integrate feature flags and Key Vault secrets into your application configuration. This example selects AppSettings, enables feature flags, and configures Key Vault with default credentials. ```csharp builder.AddAzureAppConfiguration(options => { options.Connect("connection_string") .Select("AppSettings:*") .UseFeatureFlags(ff => ff.Select("Features:*")) .ConfigureKeyVault(kv => kv.SetCredential(new DefaultAzureCredential())); }); ``` -------------------------------- ### Filter Keys Loaded Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/README.md Specify which keys to load from Azure App Configuration. This example loads only keys prefixed with 'Critical:'. Avoid loading all keys using `KeyFilter.Any` unless necessary. ```csharp .Select("Critical:*") // Only essential keys // Don't: .Select(KeyFilter.Any) to load all keys ``` -------------------------------- ### StartupOptions Class Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/types.md Configures options for initially loading data into the configuration provider. Specifies the timeout for the initial data load. ```csharp public class StartupOptions { public TimeSpan Timeout { get; set; } = TimeSpan.FromSeconds(100); } ``` -------------------------------- ### Match Kubernetes Startup Probe Timeout Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/startup-configuration.md Sets the startup timeout to 25 seconds, leaving a 5-second buffer for a 30-second Kubernetes startup probe. ```csharp // For Kubernetes with startup probe timeout of 30 seconds options.ConfigureStartupOptions(startup => { startup.Timeout = TimeSpan.FromSeconds(25); // Leave 5s buffer }); ``` -------------------------------- ### Get IConfigurationRefresher Instance Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/azure-app-configuration-options.md Obtain an IConfigurationRefresher instance to manually trigger configuration refreshes. This is useful after registering key-values for refresh. ```csharp var options = new AzureAppConfigurationOptions(); options.Connect("connection_string") .ConfigureRefresh(refresh => refresh.RegisterAll()); var refresher = options.GetRefresher(); await refresher.RefreshAsync(); ``` -------------------------------- ### Initialization Errors Handling Strategy Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/architecture.md Compares the behavior of AddAzureAppConfiguration() with optional=false (default) versus optional=true regarding error handling during application startup. ```plaintext AddAzureAppConfiguration() | +-- optional=false (default) | +-- Any error thrown +-- Application startup fails +-- Clear indication of configuration problem | +-- optional=true | +-- Errors suppressed +-- Configuration loaded from other sources only +-- Application continues ``` -------------------------------- ### Get App Configuration Endpoint Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/configuration-refresher.md Access the AppConfigurationEndpoint property to retrieve the URI of the primary Azure App Configuration store the refresher is connected to. ```csharp public Uri AppConfigurationEndpoint { get; } ``` ```csharp var refresher = options.GetRefresher(); var endpoint = refresher.AppConfigurationEndpoint; Console.WriteLine($"Connected to: {endpoint}"); ``` -------------------------------- ### Container Deployment Startup Timeout Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/startup-configuration.md Configures a startup timeout (25 seconds) to align with container startup probes, ensuring failure before the probe times out. ```csharp // Kubernetes startup probe might allow 30 seconds // Set timeout to 25 seconds to fail before probe times out options.ConfigureStartupOptions(startup => { startup.Timeout = TimeSpan.FromSeconds(25); }); ``` -------------------------------- ### Catch ArgumentNullException for Null Parameters Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/errors.md Catch ArgumentNullException when required parameters are null or empty. This example demonstrates logging the parameter name that caused the exception. ```csharp try { options.Connect(null); // ArgumentNullException } catch (ArgumentNullException ex) { Console.WriteLine($"Missing required parameter: {ex.ParamName}"); } ``` -------------------------------- ### Key Selection with Select Method Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/README.md Demonstrates how to use the `Select` method to filter which key-values are loaded from Azure App Configuration based on key name patterns and labels. ```csharp options.Select("AppSettings*") // Keys starting with "AppSettings" .Select("Database:*", "prod") // Keys starting with "Database:" with "prod" label .SelectSnapshot("backup") // All keys in "backup" snapshot ``` -------------------------------- ### Configure ASP.NET Core App with Azure App Configuration Middleware Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/aspnet-core-middleware.md Demonstrates how to integrate Azure App Configuration middleware into an ASP.NET Core application's startup process. This includes adding services and applying the middleware. ```csharp public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddAzureAppConfiguration(); services.AddControllers(); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseAzureAppConfiguration(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); } } ``` -------------------------------- ### Handle Initialization Errors (ArgumentNullException) Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/README.md Demonstrates how to catch `ArgumentNullException` during the initialization of the Azure App Configuration provider, specifically when a null connection string is provided. ```csharp try { builder.AddAzureAppConfiguration(options => { options.Connect(null); // ArgumentNullException }); } catch (ArgumentNullException ex) { Console.WriteLine($"Invalid parameter: {ex.ParamName}"); } ``` -------------------------------- ### Configure Startup Options Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/azure-app-configuration-options.md Configures the provider's behavior when loading data from Azure App Configuration at startup. This allows setting timeouts for the initial data load. ```csharp var options = new AzureAppConfigurationOptions(); options.Connect("connection_string") .ConfigureStartupOptions(startup => { startup.Timeout = TimeSpan.FromSeconds(60); }); ``` -------------------------------- ### Catch ArgumentOutOfRangeException for Out-of-Range Values Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/errors.md Catch ArgumentOutOfRangeException when parameter values fall outside the acceptable range. This example logs the parameter name, actual value, and the exception message. ```csharp try { options.ConfigureRefresh(refresh => { refresh.SetRefreshInterval(TimeSpan.FromMilliseconds(500)); // Too short }); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine($"Parameter out of range: {ex.ParamName}"); Console.WriteLine($"Actual value: {ex.ActualValue}"); Console.WriteLine($"Message: {ex.Message}"); } ``` -------------------------------- ### Reduce Keys Loaded for Startup Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/startup-configuration.md Selects only critical keys initially to reduce the number of items loaded during startup, mitigating potential timeouts. ```csharp // Load only essential keys initially options.Select("Critical:*"); ``` -------------------------------- ### StartupOptions Class Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/startup-configuration.md Represents options used when initially loading data into the configuration provider during application startup. The primary configurable property is `Timeout`. ```APIDOC ## StartupOptions ### Description Options used when initially loading data into the configuration provider during application startup. ### Properties #### Timeout - **Timeout** (TimeSpan) - Required - Maximum duration for loading configuration from App Configuration. - Default: 100 seconds - Constraints: Must be a positive TimeSpan. - Applies only to initial load during builder.Build(). - Does not apply to refresh operations after startup. ### Behavior on Timeout - If timeout exceeded and `optional` is false: `TimeoutException` is thrown. - If timeout exceeded and `optional` is true: Configuration loads from remaining sources without Azure App Configuration data. ### Example ```csharp var configBuilder = new ConfigurationBuilder(); configBuilder.AddAzureAppConfiguration(options => { options.Connect("connection_string") .Select("Settings:*") .ConfigureStartupOptions(startup => { startup.Timeout = TimeSpan.FromSeconds(60); }); }); var config = configBuilder.Build(); // All selected keys must be loaded within 60 seconds ``` -------------------------------- ### Catch ArgumentException for Invalid Configuration Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/errors.md Catch ArgumentException to handle invalid argument values provided to configuration methods. This example shows how to log the exception message and the parameter name. ```csharp try { options.Select("my:*key") .ConfigureRefresh(refresh => { refresh.Register("key", "label", false) .SetRefreshInterval(TimeSpan.FromSeconds(0.5)); // Too short }); } catch (ArgumentException ex) { Console.WriteLine($"Invalid configuration: {ex.Message}"); Console.WriteLine($"Parameter: {ex.ParamName}"); } ``` -------------------------------- ### Inject Configuration into a Service Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/README.md Demonstrates how to inject the `IConfiguration` service into a custom service to access configuration settings. ```csharp public MyService(IConfiguration config) { var setting = config["SettingKey"]; } ``` -------------------------------- ### Development Environment Startup Timeout Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/startup-configuration.md Sets a short timeout (10 seconds) for faster failure during development environments. ```csharp var timeout = app.Environment.IsDevelopment() ? TimeSpan.FromSeconds(10) : TimeSpan.FromSeconds(100); options.ConfigureStartupOptions(startup => { startup.Timeout = timeout; }); ``` -------------------------------- ### Key Vault Secret Refresh Intervals Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/README.md Configure specific refresh intervals for secrets stored in Azure Key Vault. This example sets a 5-minute refresh for 'DatabasePassword' and a 10-minute refresh for all other secrets. ```csharp options.ConfigureKeyVault(kv => { kv.SetSecretRefreshInterval("DatabasePassword", TimeSpan.FromMinutes(5)) .SetSecretRefreshInterval(TimeSpan.FromMinutes(10)); // Others }); ``` -------------------------------- ### Match Docker Health Check Timeout Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/startup-configuration.md Sets the startup timeout to 50 seconds for a 60-second Docker health check timeout. ```csharp // For Docker with health check timeout of 60 seconds options.ConfigureStartupOptions(startup => { startup.Timeout = TimeSpan.FromSeconds(50); }); ``` -------------------------------- ### Key Vault Secret Resolution Example Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/README.md Illustrates how the provider automatically resolves secrets stored in Azure Key Vault when they are referenced in Azure App Configuration. Assumes the secret is stored with a specific content type. ```csharp // In App Configuration, store: // Key: "Database:Password" // Value: {"uri":"https://vault.azure.net/secrets/db-pass"} // ContentType: "application/vnd.microsoft.appconfig.keyvaultsecret+json" options.ConfigureKeyVault(kv => { kv.SetCredential(new DefaultAzureCredential()); }); // Provider automatically resolves the secret var password = config["Database:Password"]; ``` -------------------------------- ### Production Environment Startup Timeout Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/startup-configuration.md Sets a longer timeout (150 seconds) to accommodate network variability in production environments. ```csharp options.ConfigureStartupOptions(startup => { startup.Timeout = TimeSpan.FromSeconds(150); }); ``` -------------------------------- ### Catching InvalidOperationException for Mixed Refresh Registration Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/errors.md This catch pattern specifically addresses invalid operation scenarios, such as attempting to mix 'Register' and 'RegisterAll' methods within the same refresh configuration. It helps diagnose configuration setup errors. ```csharp try { options.ConfigureRefresh(refresh => { refresh.Register("key"); refresh.RegisterAll(); // Error - mixed register methods }); } catch (InvalidOperationException ex) { Console.WriteLine($"Configuration error: {ex.Message}"); } ``` -------------------------------- ### Disable Azure App Configuration Provider Externally Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/health-checks.md Shows how to disable the Azure App Configuration provider using an environment variable. This is a best practice for resilience, ensuring the application can start even if App Configuration is unavailable. ```csharp // Set AZURE_APP_CONFIGURATION_PROVIDER_DISABLED=true to disable var builder = new ConfigurationBuilder(); builder.AddAzureAppConfiguration(options => { // Configuration here }, optional: true); // Also use optional=true for resilience ``` -------------------------------- ### Multiple Selection Sets for Configuration Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/README.md Load configuration settings from multiple distinct sets of keys. This allows for granular control over which settings are applied. ```csharp options.Select("Critical:*") .Select("Features:*") .Select("Database:*"); ``` -------------------------------- ### ConfigurationBuilder with Key Selection Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/configuration.md Configure the provider to select specific key prefixes from App Configuration during the build process. ```csharp builder.AddAzureAppConfiguration(options => { options.Connect("connection_string") .Select("AppSettings:*") .Select("Database:*"); }); ``` -------------------------------- ### Client Factory Pattern Overview Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/architecture.md Diagram of the client factory pattern, showing optional custom factory usage or default creation via connection string/endpoint. ```plaintext AzureAppConfigurationOptions | +--(optional) SetClientFactory() | | | +-- Custom IAzureClientFactory | +-- or Connect() with connection string/endpoint | +-- Creates default client factory | +-- Creates ConfigurationClient instances ``` -------------------------------- ### ConfigureStartupOptions Method Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/startup-configuration.md Configures the provider's behavior during the initial data load from Azure App Configuration using a callback action. ```csharp public AzureAppConfigurationOptions ConfigureStartupOptions( Action configure) ``` -------------------------------- ### Increase Startup Timeout Solution Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/startup-configuration.md Increases the startup timeout to 180 seconds as a solution for timeout errors during application startup. ```csharp startup.Timeout = TimeSpan.FromSeconds(180); ``` -------------------------------- ### Set Custom Client Factory Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/architecture.md Allows for the creation of a custom ConfigurationClient, enabling custom logic for client instantiation and configuration. ```csharp options.SetClientFactory(new MyCustomFactory()); ``` -------------------------------- ### Connect using Connection String Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/README.md Provides the simplest method to connect to Azure App Configuration using a connection string. Recommended for local development or environments with shared credentials. ```csharp options.Connect("Endpoint=https://store.azconfig.io;Id=xxx;Secret=yyy"); ``` -------------------------------- ### ConfigureStartupOptions Method Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/startup-configuration.md Configures the provider's behavior when loading data from Azure App Configuration on startup. This method allows for fine-grained control over initial data loading parameters. ```APIDOC ## ConfigureStartupOptions ```csharp public AzureAppConfigurationOptions ConfigureStartupOptions( Action configure) ``` ### Description Configure the provider behavior when loading data from Azure App Configuration on startup. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp options.ConfigureStartupOptions(startup => { startup.Timeout = TimeSpan.FromSeconds(120); }); ``` ### Response #### Success Response (200) Returns the current `AzureAppConfigurationOptions` instance for chaining. #### Response Example None provided in source. ``` -------------------------------- ### Connect to Azure App Configuration using Multiple Connection Strings Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/azure-app-configuration-options.md Connect the provider to an Azure App Configuration store and its replicas via a list of connection strings. This is useful for high availability scenarios. ```csharp var options = new AzureAppConfigurationOptions(); var connectionStrings = new[] { "Endpoint=https://primary.azconfig.io;Id=xxx;Secret=yyy", "Endpoint=https://replica.azconfig.io;Id=xxx;Secret=yyy" }; options.Connect(connectionStrings); ``` -------------------------------- ### Basic Configuration Loading Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/README.md Loads configuration settings from Azure App Configuration using a connection string. This is the simplest way to integrate the provider. ```csharp var builder = new ConfigurationBuilder(); builder.AddAzureAppConfiguration("connection_string"); var config = builder.Build(); var value = config["SettingKey"]; ``` -------------------------------- ### Graceful Degradation with Optional App Configuration Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/errors.md Implement graceful degradation by loading default configuration when Azure App Configuration is unavailable. Set 'optional: true' to prevent exceptions during startup. ```csharp var builder = new ConfigurationBuilder(); builder.AddJsonFile("appsettings.json"); try { builder.AddAzureAppConfiguration(options => { options.Connect("connection_string") .Select("AppSettings:*"); }, optional: true); // Don't throw if App Configuration fails } catch (Exception ex) { Console.WriteLine($"Warning: Could not load Azure App Configuration: {ex.Message}"); } var config = builder.Build(); ``` -------------------------------- ### Handle Configuration Errors (InvalidOperationException) Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/README.md Shows how to catch `InvalidOperationException` when attempting to configure refresh settings with duplicate key registrations. ```csharp try { options.ConfigureRefresh(refresh => { refresh.Register("key") .Register("key"); // Duplicate }); } catch (InvalidOperationException ex) { Console.WriteLine($"Configuration error: {ex.Message}"); } ``` -------------------------------- ### Connect (Connection Strings - Multiple) Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/azure-app-configuration-options.md Connects the provider to an Azure App Configuration store and its replicas using a list of connection strings. This supports failover scenarios by providing multiple endpoints. ```APIDOC ## Connect (Connection Strings - Multiple) ### Description Connect the provider to an Azure App Configuration store and its replicas via a list of connection strings. ### Method POST ### Endpoint /connect ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **connectionStrings** (IEnumerable) - Required - Used to authenticate with Azure App Configuration ### Request Example ```csharp var options = new AzureAppConfigurationOptions(); var connectionStrings = new[] { "Endpoint=https://primary.azconfig.io;Id=xxx;Secret=yyy", "Endpoint=https://replica.azconfig.io;Id=xxx;Secret=yyy" }; options.Connect(connectionStrings); ``` ### Response #### Success Response (200) - **AzureAppConfigurationOptions** - The current instance for chaining. #### Response Example ```csharp // Returns an instance of AzureAppConfigurationOptions ``` ### Throws - **ArgumentNullException**: If connectionStrings is null or empty - **ArgumentException**: If connectionStrings contains duplicate values ``` -------------------------------- ### Dynamic Refresh Registration and Interval Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/README.md Configures dynamic refresh by registering specific keys to monitor and setting the interval for checking updates. It also shows how to manually trigger a refresh. ```csharp options.ConfigureRefresh(refresh => { refresh.Register("Settings:Version", refreshAll: true) // Refresh all when this changes .Register("Features:Enabled") // Refresh only this key .SetRefreshInterval(TimeSpan.FromSeconds(30)); // Check every 30 seconds }); // Later in code: var refresher = options.GetRefresher(); await refresher.RefreshAsync(); ``` -------------------------------- ### Development Configuration with JSON Fallback Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/README.md Configure your .NET application to load settings from `appsettings.json` and environment-specific JSON files, with an optional fallback to Azure App Configuration. This pattern is useful for local development. ```csharp var builder = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); builder.AddAzureAppConfiguration(options => { options.Connect(connectionString) .Select("Settings:*"); }, optional: true); var config = builder.Build(); ``` -------------------------------- ### ConfigureStartupOptions Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/azure-app-configuration-options.md Configures the provider behavior when loading data from Azure App Configuration on startup. ```APIDOC ## ConfigureStartupOptions ### Description Configure the provider behavior when loading data from Azure App Configuration on startup. ### Method Signature ```csharp public AzureAppConfigurationOptions ConfigureStartupOptions( Action configure) ``` ### Parameters #### configure - **Type**: `Action` - **Description**: A callback used to configure startup options. ### Returns - **Type**: `AzureAppConfigurationOptions` - **Description**: The current instance for chaining. ### Example ```csharp var options = new AzureAppConfigurationOptions(); options.Connect("connection_string") .ConfigureStartupOptions(startup => { startup.Timeout = TimeSpan.FromSeconds(60); }); ``` ``` -------------------------------- ### Add Azure App Configuration using Multiple Connection Strings Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/azure-app-configuration-extensions.md Adds key-value data from a primary Azure App Configuration store and one or more replica stores using connection strings. This overload loads all key-values with no label. ```csharp var builder = new ConfigurationBuilder(); var connectionStrings = new[] { "Endpoint=https://primary.azconfig.io;Id=xxx;Secret=yyy", "Endpoint=https://replica.azconfig.io;Id=xxx;Secret=yyy" }; builder.AddAzureAppConfiguration(connectionStrings); var configuration = builder.Build(); ``` -------------------------------- ### Configure ASP.NET Core with Feature Flags Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/aspnet-core-middleware.md Connect to Azure App Configuration and enable feature flag selection. Configure refresh intervals for both settings and feature flags. ```csharp configBuilder.AddAzureAppConfiguration(options => { options.Connect(connectionString) .Select("Settings:*") .UseFeatureFlags(ff => { ff.Select("FeatureFlags:*") .SetRefreshInterval(TimeSpan.FromSeconds(30)); }) .ConfigureRefresh(refresh => { refresh.Register("Settings:Version", refreshAll: true) .SetRefreshInterval(TimeSpan.FromSeconds(30)); }); }); ``` -------------------------------- ### Monitor Startup Configuration Load Time Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/startup-configuration.md Measures and logs the elapsed time for loading configuration from Azure App Configuration during application startup. ```csharp var sw = Stopwatch.StartNew(); var configBuilder = new ConfigurationBuilder(); configBuilder.AddAzureAppConfiguration(options => { options.Connect(connectionString) .Select("Settings:*") .ConfigureStartupOptions(startup => { startup.Timeout = TimeSpan.FromSeconds(100); }); }); var config = configBuilder.Build(); sw.Stop(); Console.WriteLine($"Configuration loaded in {sw.ElapsedMilliseconds}ms"); ``` -------------------------------- ### Configuration Builder Integration Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/architecture.md Illustrates how the Azure App Configuration provider is integrated into the .NET configuration builder via extension methods. ```plaintext IConfigurationBuilder | +-- AddAzureAppConfiguration() [Extension Method] | +-- Creates AzureAppConfigurationSource | +-- AzureAppConfigurationProvider [IConfigurationProvider] ``` -------------------------------- ### Add Azure App Configuration with Advanced Options Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/azure-app-configuration-extensions.md Use this overload to configure Azure App Configuration options for advanced scenarios like selecting keys by prefix, filtering by labels, configuring dynamic refresh, using feature flags, and resolving Key Vault references. It requires a callback action to configure the options. ```csharp public static IConfigurationBuilder AddAzureAppConfiguration( this IConfigurationBuilder configurationBuilder, Action action, bool optional = false) ``` ```csharp var builder = new ConfigurationBuilder(); builder.AddAzureAppConfiguration(options => { options.Connect("Endpoint=https://mystore.azconfig.io;Id=xxx;Secret=yyy") .Select("AppSettings*") .Select("Database:ConnectionString", "prod") .ConfigureRefresh(refresh => { refresh.Register("AppSettings:Version", refreshAll: true) .SetRefreshInterval(TimeSpan.FromSeconds(30)); }); }); var configuration = builder.Build(); ``` -------------------------------- ### Configure Refresh Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/azure-app-configuration-options.md Configure refresh for key-values in the configuration provider. The callback must call either Register() or RegisterAll(), not both. ```csharp public AzureAppConfigurationOptions ConfigureRefresh( Action configure) ``` ```csharp var options = new AzureAppConfigurationOptions(); options.Connect("connection_string") .Select("AppSettings:*") .ConfigureRefresh(refresh => { refresh.Register("AppSettings:Version", refreshAll: true) .SetRefreshInterval(TimeSpan.FromSeconds(30)); }); ``` -------------------------------- ### Connect with Multiple Connection Strings Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/README.md Use when high availability with automatic failover is needed. Provide an array of connection strings for primary and replica endpoints. ```csharp options.Connect(new[] { "Endpoint=https://primary.azconfig.io;...", "Endpoint=https://replica.azconfig.io;..." }); ``` -------------------------------- ### RegisterAll Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/refresh-options.md Registers all key-values not explicitly configured in `ConfigureRefresh()` to be refreshed. This method should be called only once per `ConfigureRefresh()` invocation and cannot be used with `Register()`. ```APIDOC ## RegisterAll ### Description Register all key-values loaded outside of `ConfigureRefresh()` to be refreshed when the configuration provider's `IConfigurationRefresher` triggers a refresh. Cannot be used together with `Register()`. Must be called exactly once per `ConfigureRefresh()` invocation. ### Method ```csharp public AzureAppConfigurationRefreshOptions RegisterAll() ``` ### Throws - **InvalidOperationException** - If used with `Register()` in the same ConfigureRefresh call, or if ConfigureRefresh is called multiple times ### Example ```csharp options.ConfigureRefresh(refresh => { refresh.RegisterAll() .SetRefreshInterval(TimeSpan.FromSeconds(30)); }); ``` ``` -------------------------------- ### Configure Environment-Specific Settings Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/startup-configuration.md Load configuration from environment-specific JSON files (e.g., appsettings.Development.json) before connecting to Azure App Configuration. This snippet demonstrates setting up the configuration builder for a .NET web application. ```csharp var builder = WebApplication.CreateBuilder(args); var env = builder.Environment; // In appsettings.Development.json builder.Configuration.AddJsonFile($"appsettings.{env.EnvironmentName}.json"); builder.Configuration.AddAzureAppConfiguration(options => { options.Connect(connectionString) .ConfigureStartupOptions(startup => { if (env.IsDevelopment()) startup.Timeout = TimeSpan.FromSeconds(30); else startup.Timeout = TimeSpan.FromSeconds(100); }); }); ``` -------------------------------- ### Select Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/azure-app-configuration-options.md Specify what key-values to include in the configuration provider. Can be called multiple times to include multiple sets of key-values. The asterisk (*) can be added to the end of keyFilter to return all key-values whose key begins with the filter. ```APIDOC ## Select ### Description Specify what key-values to include in the configuration provider. Can be called multiple times to include multiple sets of key-values. The asterisk (*) can be added to the end of keyFilter to return all key-values whose key begins with the filter. ### Method `public AzureAppConfigurationOptions Select(string keyFilter, string labelFilter = LabelFilter.Null, IEnumerable tagFilters = null)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters Table | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | keyFilter | string | — | The key filter. Use `*` for wildcard matching at the end | | labelFilter | string | LabelFilter.Null | The label filter. Use LabelFilter.Null for null label (default) | | tagFilters | IEnumerable | null | Tag filters in format "tagName=tagValue". Maximum 5 filters | ### Returns `AzureAppConfigurationOptions` — The current instance for chaining. ### Throws | Error | Condition | |-------|-----------| | ArgumentNullException | If keyFilter is null or empty | | ArgumentException | If labelFilter contains `*` or `,`, or tagFilters are invalid | ### Example ```csharp var options = new AzureAppConfigurationOptions(); options.Connect("connection_string") .Select("AppSettings*") .Select("Database:ConnectionString", "prod") .Select("Features:*", "beta", new[] { "environment=staging" }); ``` ``` -------------------------------- ### Register (Key and RefreshAll) Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/refresh-options.md Registers an individual key-value to be refreshed. If refreshAll is true, a change in this key's value will trigger a refresh of all key-values used by the configuration provider. The key uses the null label. ```APIDOC ## Register (Key and RefreshAll) ### Description Register the specified individual key-value to be refreshed when the configuration provider's `IConfigurationRefresher` triggers a refresh. The key-value will use the null label. ### Method ```csharp public AzureAppConfigurationRefreshOptions Register(string key, bool refreshAll) ``` ### Parameters #### Path Parameters - **key** (string) - Required - Key of the key-value. Cannot function as a key filter for a collection of key-values - **refreshAll** (bool) - Required - If true, a change in the value of this key refreshes all key-values being used by the configuration provider ### Throws - **ArgumentNullException** - If key is null or empty ### Example ```csharp options.ConfigureRefresh(refresh => { refresh.Register("AppSettings:Version") .Register("Settings:ShouldRefreshAll", refreshAll: true) .SetRefreshInterval(TimeSpan.FromSeconds(30)); }); ``` ``` -------------------------------- ### Configure Client Options for Key Vault References Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/key-vault-options.md Use ConfigureClientOptions to customize the SecretClientOptions used for connecting to key vaults when no SecretClient is explicitly registered. This configuration does not affect clients registered via Register(). ```csharp options.ConfigureKeyVault(kv => { kv.SetCredential(new DefaultAzureCredential()) .ConfigureClientOptions(client => { client.Retry.MaxRetries = 3; }); }); ``` -------------------------------- ### Set Connection String Using User Secrets in Development Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/aspnet-core-middleware.md Configure the App Configuration connection string using the `dotnet user-secrets` command for local development. ```bash dotnet user-secrets set "AppConfig:ConnectionString" "" ``` -------------------------------- ### Select Snapshot Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/azure-app-configuration-options.md Specify a snapshot and include its contained key-values in the configuration provider. Can be called multiple times to include key-values from multiple snapshots. ```csharp public AzureAppConfigurationOptions SelectSnapshot(string name) ``` ```csharp var options = new AzureAppConfigurationOptions(); options.Connect("connection_string") .SelectSnapshot("prod-snapshot") .SelectSnapshot("features-snapshot"); ``` -------------------------------- ### Add Azure App Configuration using Connection String Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/azure-app-configuration-extensions.md Adds key-value data from an Azure App Configuration store using a connection string. This overload loads all key-values with no label. ```csharp var builder = new ConfigurationBuilder(); builder.AddAzureAppConfiguration("Endpoint=https://mystore.azconfig.io;Id=xxx;Secret=yyy"); var configuration = builder.Build(); ``` -------------------------------- ### Connect (URIs and Credential - Multiple) Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/azure-app-configuration-options.md Connects the provider to an Azure App Configuration store and its replicas using a list of URIs and a token credential. This enables robust connectivity with multiple endpoints and token authentication. ```APIDOC ## Connect (URIs and Credential - Multiple) ### Description Connect the provider to an Azure App Configuration store and its replicas using a list of endpoints and a token credential. ### Method POST ### Endpoint /connect ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **endpoints** (IEnumerable) - Required - The list of endpoints of an Azure App Configuration store and its replicas - **credential** (TokenCredential) - Required - Token credential to use to connect ### Request Example ```csharp var options = new AzureAppConfigurationOptions(); var endpoints = new[] { new Uri("https://primary.azconfig.io"), new Uri("https://replica.azconfig.io") }; var credential = new DefaultAzureCredential(); options.Connect(endpoints, credential); ``` ### Response #### Success Response (200) - **AzureAppConfigurationOptions** - The current instance for chaining. #### Response Example ```csharp // Returns an instance of AzureAppConfigurationOptions ``` ### Throws - **ArgumentNullException**: If endpoints is null or empty, or credential is null - **ArgumentException**: If endpoints contains duplicate values ``` -------------------------------- ### Inject Refresher Provider and Trigger Refresh Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/README.md Shows how to inject `IConfigurationRefresherProvider` into a service and manually trigger a refresh for all registered configuration refreshers. ```csharp public MyService(IConfigurationRefresherProvider refresherProvider) { foreach (var refresher in refresherProvider.Refreshers) { await refresher.TryRefreshAsync(); } } ``` -------------------------------- ### ConfigurationBuilder with Multiple Endpoints and Load Balancing Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/configuration.md Configure the provider to connect to multiple App Configuration endpoints with load balancing enabled. This is useful for high availability scenarios. ```csharp builder.AddAzureAppConfiguration(options => { options.Connect(new[] { "Endpoint=https://primary.azconfig.io;...", "Endpoint=https://replica.azconfig.io;..." }) .LoadBalancingEnabled = true .Select("Settings:*"); }); ``` -------------------------------- ### Register all key-values for refresh Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/refresh-options.md Register all key-values that were loaded outside of `ConfigureRefresh()` to be refreshed. This is a convenient way to ensure all configuration settings are monitored for changes. This method cannot be used in conjunction with `Register()` and must be called only once per `ConfigureRefresh()` invocation. ```csharp options.ConfigureRefresh(refresh => { refresh.RegisterAll() .SetRefreshInterval(TimeSpan.FromSeconds(30)); }); ``` -------------------------------- ### Diagnose Configuration Validation Errors at Startup Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/errors.md This code shows how to validate Azure App Configuration settings during application startup by attempting to build the configuration. It catches specific argument-related exceptions and re-throws them as InvalidOperationException with more context for easier diagnosis. ```csharp private void ValidateConfiguration(AzureAppConfigurationOptions options) { try { // Try to build with the options var builder = new ConfigurationBuilder(); builder.AddAzureAppConfiguration(o => { // Apply same configuration }); } catch (ArgumentException argEx) { throw new InvalidOperationException( $"Invalid App Configuration settings: {argEx.Message}. " + $"Check connection string, filters, and labels.", argEx); } catch (ArgumentNullException nullEx) { throw new InvalidOperationException( $"Missing required configuration: {nullEx.ParamName}", nullEx); } } ``` -------------------------------- ### Connect to Azure App Configuration using Multiple Endpoints and Token Credential Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/azure-app-configuration-options.md Connect the provider to an Azure App Configuration store and its replicas using a list of endpoints and a token credential. This provides redundancy and failover capabilities. ```csharp var options = new AzureAppConfigurationOptions(); var endpoints = new[] { new Uri("https://primary.azconfig.io"), new Uri("https://replica.azconfig.io") }; var credential = new DefaultAzureCredential(); options.Connect(endpoints, credential); ``` -------------------------------- ### Configure Startup Timeout for Azure App Configuration Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/health-checks.md Set a custom startup timeout for the Azure App Configuration provider initialization. This ensures the application waits for a specified duration for the configuration to load. ```csharp services.AddAzureAppConfiguration(); services.Configure(options => { options.Timeout = TimeSpan.FromSeconds(60); }); ``` -------------------------------- ### Configure ASP.NET Core with Key Vault Integration Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/aspnet-core-middleware.md Connect to Azure App Configuration, configure Key Vault integration using DefaultAzureCredential, and set up automatic refresh for all settings. ```csharp configBuilder.AddAzureAppConfiguration(options => { options.Connect(connectionString) .Select("Settings:*") .ConfigureKeyVault(kv => { kv.SetCredential(new DefaultAzureCredential()); }) .ConfigureRefresh(refresh => { refresh.RegisterAll() .SetRefreshInterval(TimeSpan.FromSeconds(60)); }); }); ``` -------------------------------- ### Register a key-value with label for refresh Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/refresh-options.md Register a specific key-value with a given label to be refreshed. This allows for refreshing configuration values that are specific to a certain environment or deployment. The `refreshAll` parameter controls whether a change in this key-value triggers a refresh of all monitored settings. ```csharp options.ConfigureRefresh(refresh => { refresh.Register("Database:Host", "prod") .Register("Features:EnableNewUI", "staging", refreshAll: true) .SetRefreshInterval(TimeSpan.FromSeconds(60)); }); ``` -------------------------------- ### Connect (Connection String) Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/azure-app-configuration-options.md Connects the provider to the Azure App Configuration service using a single connection string. This method is useful for authenticating with a single App Configuration store. ```APIDOC ## Connect (Connection String) ### Description Connect the provider to the Azure App Configuration service via a connection string. ### Method POST ### Endpoint /connect ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **connectionString** (string) - Required - Used to authenticate with Azure App Configuration ### Request Example ```csharp var options = new AzureAppConfigurationOptions(); options.Connect("Endpoint=https://mystore.azconfig.io;Id=xxx;Secret=yyy"); ``` ### Response #### Success Response (200) - **AzureAppConfigurationOptions** - The current instance for chaining. #### Response Example ```csharp // Returns an instance of AzureAppConfigurationOptions ``` ### Throws - **ArgumentNullException**: If connectionString is null or whitespace ``` -------------------------------- ### Configuration with Dynamic Refresh Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/README.md Configures the provider to dynamically refresh configuration values at runtime. It specifies which settings to monitor and how often to check for updates. ```csharp builder.AddAzureAppConfiguration(options => { options.Connect("connection_string") .Select("Settings:*") .ConfigureRefresh(refresh => { refresh.Register("Settings:Version", refreshAll: true) .SetRefreshInterval(TimeSpan.FromSeconds(30)); }); }); var refresher = options.GetRefresher(); await refresher.RefreshAsync(); ``` -------------------------------- ### ConfigureRefresh Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/azure-app-configuration-options.md Configure refresh for key-values in the configuration provider. The callback must call either `Register()` or `RegisterAll()`, not both. ```APIDOC ## ConfigureRefresh ### Description Configure refresh for key-values in the configuration provider. The callback must call either `Register()` or `RegisterAll()`, not both. ### Method `public AzureAppConfigurationOptions ConfigureRefresh(Action configure)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters Table | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | configure | Action | — | A callback used to configure refresh options | ### Returns `AzureAppConfigurationOptions` — The current instance for chaining. ### Throws | Error | Condition | |-------|-----------| | InvalidOperationException | If called multiple times when RegisterAll is used, or if neither Register nor RegisterAll is called | ### Example ```csharp var options = new AzureAppConfigurationOptions(); options.Connect("connection_string") .Select("AppSettings:*") .ConfigureRefresh(refresh => { refresh.Register("AppSettings:Version", refreshAll: true) .SetRefreshInterval(TimeSpan.FromSeconds(30)); }); ``` ``` -------------------------------- ### Configuration Access via IConfiguration Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/architecture.md Shows how configuration values loaded by the AzureAppConfigurationProvider are accessed through the standard .NET IConfiguration interface. ```plaintext IConfiguration [Standard .NET Interface] | +-- Values loaded from AzureAppConfigurationProvider +-- Accessible via dependency injection +-- Hierarchical key access (using ':' separator) ``` -------------------------------- ### Use Push Notifications for Updates Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/README.md Instead of polling, leverage push notifications for immediate configuration updates. This requires a `refresher` object and a `pushNotification` payload. ```csharp // Instead of polling, use push notifications for immediate updates refresher.ProcessPushNotification(pushNotification); ``` -------------------------------- ### Select Key-Values Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/azure-app-configuration-options.md Specify which key-values to include in the configuration provider. Can be called multiple times to include multiple sets of key-values. Wildcard matching is supported at the end of the key filter. ```csharp public AzureAppConfigurationOptions Select( string keyFilter, string labelFilter = LabelFilter.Null, IEnumerable tagFilters = null) ``` ```csharp var options = new AzureAppConfigurationOptions(); options.Connect("connection_string") .Select("AppSettings*") .Select("Database:ConnectionString", "prod") .Select("Features:*", "beta", new[] { "environment=staging" }); ``` -------------------------------- ### Connect (URI and Credential) Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/azure-app-configuration-options.md Connects the provider to Azure App Configuration using a URI endpoint and token credentials. This is suitable for scenarios where token-based authentication is preferred. ```APIDOC ## Connect (URI and Credential) ### Description Connect the provider to Azure App Configuration using endpoint and token credentials. ### Method POST ### Endpoint /connect ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **endpoint** (Uri) - Required - The endpoint of the Azure App Configuration to connect to - **credential** (TokenCredential) - Required - Token credentials to use to connect ### Request Example ```csharp var options = new AzureAppConfigurationOptions(); var endpoint = new Uri("https://mystore.azconfig.io"); var credential = new DefaultAzureCredential(); options.Connect(endpoint, credential); ``` ### Response #### Success Response (200) - **AzureAppConfigurationOptions** - The current instance for chaining. #### Response Example ```csharp // Returns an instance of AzureAppConfigurationOptions ``` ### Throws - **ArgumentNullException**: If endpoint or credential is null ``` -------------------------------- ### Map Setting with Custom Logic Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/architecture.md Applies a custom transformation to a configuration setting. Multiple mappers can be chained for complex data manipulation. ```csharp options.Map(async (setting) => { // Custom transformation logic return setting; }); ``` -------------------------------- ### Register (Key, Label, and RefreshAll) Source: https://github.com/azure/appconfiguration-dotnetprovider/blob/main/_autodocs/api-reference/refresh-options.md Registers an individual key-value with a specified label to be refreshed. The refreshAll parameter controls whether a change in this key triggers a refresh of all settings. Defaults are provided for label and refreshAll. ```APIDOC ## Register (Key, Label, and RefreshAll) ### Description Register the specified individual key-value to be refreshed when the configuration provider's `IConfigurationRefresher` triggers a refresh. Specify the label to select the correct key-value variant. ### Method ```csharp public AzureAppConfigurationRefreshOptions Register(string key, string label = LabelFilter.Null, bool refreshAll = false) ``` ### Parameters #### Path Parameters - **key** (string) - Required - Key of the key-value. Cannot function as a key filter for a collection of key-values - **label** (string) - Optional - Label of the key-value. Defaults to `LabelFilter.Null` - **refreshAll** (bool) - Optional - If true, a change in the value of this key refreshes all key-values being used by the configuration provider. Defaults to `false` ### Throws - **ArgumentNullException** - If key is null or empty ### Example ```csharp options.ConfigureRefresh(refresh => { refresh.Register("Database:Host", "prod") .Register("Features:EnableNewUI", "staging", refreshAll: true) .SetRefreshInterval(TimeSpan.FromSeconds(60)); }); ``` ```