Platform Preferences
The Platform Preferences provider wraps the native platform preferences (Android SharedPreferences, iOS NSUserDefaults) as an IConfiguration source. Unlike most providers, this one supports write-back - you can set values via IConfiguration and they will be persisted across app restarts.
var config = new ConfigurationBuilder() .AddPlatformPreferences() .Build();Write-Back Support
Section titled “Write-Back Support”You can write values directly through IConfiguration:
IConfiguration config = ...; // buildconfig["key"] = "value"; // persists to platform preferencesWriting a value will:
- Persist the value to the platform’s native preferences store
- Trigger change notifications via
IOptionsMonitor<T>
Change Notifications
Section titled “Change Notifications”When combined with IOptionsMonitor<T>, you get reactive updates whenever a preference value changes:
services.Configure<MySettings>(config.GetSection("MySettings"));
// In your service/viewmodelpublic class MyService{ public MyService(IOptionsMonitor<MySettings> options) { options.OnChange(settings => { // React to configuration changes }); }}Platform Implementations
Section titled “Platform Implementations”| Platform | Backing Store |
|---|---|
| Android | SharedPreferences |
| iOS / Mac Catalyst | NSUserDefaults |