Skip to content
Shiny Controls v1.0 - The Ultra Control Suite for .NET MAUI & BlazorO...M...G!

Remote Configuration

NuGet package Shiny.Extensions.Configuration

The Remote Configuration provider allows you to fetch configuration from an HTTP endpoint and cache it locally. This is useful for feature flags, A/B testing, or any scenario where you need server-driven configuration.

The easiest way to add remote configuration in a MAUI app is with the MauiAppBuilder extension:

builder.AddRemoteConfigurationMaui("https://myserver.com/config");

This will:

  • Fetch configuration from the specified URI
  • Cache it locally as remotesettings.json in the app’s data directory
  • Register IRemoteConfigurationProvider in the DI container

You can specify a custom local cache file name:

builder.AddRemoteConfigurationMaui(
"https://myserver.com/config",
configurationFileName: "myconfig.json"
);

If your server requires custom headers, authentication, or returns a non-standard format, you can supply a custom data retrieval function:

builder.AddRemoteConfigurationMaui(
"https://myserver.com/config",
getData: async (remoteConfig, cancellationToken) =>
{
using var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("X-Api-Key", "my-key");
var response = await httpClient.GetStringAsync(remoteConfig.Uri, cancellationToken);
return response;
}
);

You can also add remote configuration directly to an IConfigurationBuilder:

builder.Configuration.AddRemoteMaui(
"https://myserver.com/config",
configurationFileName: "remotesettings.json"
);

When registered via the MAUI extension, IRemoteConfigurationProvider is available in the DI container. It extends IConfigurationProvider and adds:

public interface IRemoteConfigurationProvider : IConfigurationProvider
{
DateTimeOffset? LastLoaded { get; }
Task LoadAsync(CancellationToken cancellationToken = default);
}

You can manually refresh the remote configuration at any time:

public class MyService
{
readonly IRemoteConfigurationProvider remoteConfig;
public MyService(IRemoteConfigurationProvider remoteConfig)
{
this.remoteConfig = remoteConfig;
}
public async Task RefreshConfig()
{
await remoteConfig.LoadAsync();
// Configuration is now updated
// IOptionsMonitor<T> will fire change notifications
}
}

Combine remote configuration with IOptionsMonitor<T> to react to configuration changes:

services.Configure<FeatureFlags>(config.GetSection("FeatureFlags"));
public class MyViewModel
{
public MyViewModel(
IOptionsMonitor<FeatureFlags> options,
IRemoteConfigurationProvider remoteConfig)
{
options.OnChange(flags =>
{
// React to remote config changes
});
}
}