Stores
Persist class properties across sessions with a single line of code. Shiny Stores provides a cross-platform key/value store abstraction that works on iOS, Android, Windows, and Blazor WebAssembly. Swap between Preferences, Secure Storage, Local Storage, and more — all behind the same API.
Features
Section titled “Features”- Unified key/value store interface across all platforms
- Built-in stores for Preferences, Secure Storage, Local Storage, Session Storage, and In-Memory
- Persistent services — bind
INotifyPropertyChangedobjects to a store and property changes are saved automatically - Integrates with Shiny Reflector for AOT-safe, reflection-free binding
- Custom store support — implement
IKeyValueStorefor your own storage backend
-
Install the NuGet package:
Terminal window dotnet add package Shiny.Extensions.Stores -
Register stores in your DI container:
builder.Services.AddShinyStores(); -
For Blazor WebAssembly, also install and register the web stores:
Terminal window dotnet add package Shiny.Extensions.Stores.Webbuilder.Services.AddShinyWebAssemblyStores();
Available Stores
Section titled “Available Stores”Each platform provides different store implementations, identified by a string alias:
| Platform | Alias | Implementation |
|---|---|---|
| Android | settings | SharedPreferences |
| Android | secure | EncryptedSharedPreferences |
| iOS / macOS | settings | NSUserDefaults |
| iOS / macOS | secure | Keychain |
| Windows | settings | ApplicationData.LocalSettings |
| Windows | secure | Secure Storage |
| Blazor WebAssembly | settings | localStorage |
| Blazor WebAssembly | session | sessionStorage |
| All | memory | In-memory dictionary (great for testing) |
Using Stores Directly
Section titled “Using Stores Directly”Inject IKeyValueStoreFactory to access any store by alias:
public class SettingsService(IKeyValueStoreFactory storeFactory){ public void SaveTheme(string theme) { var store = storeFactory.GetStore("settings"); store.Set("theme", theme); }
public string GetTheme() { var store = storeFactory.GetStore("settings"); return store.Get<string>("theme", "light"); }
public void SaveToken(string token) { var store = storeFactory.GetStore("secure"); store.Set("auth_token", token); }}Store Extension Methods
Section titled “Store Extension Methods”store.Get<T>(key, defaultValue); // Get with a default fallbackstore.GetRequired<T>(key); // Throws if key is not foundstore.SetOrRemove(key, value); // Removes the key if value is nullstore.SetDefault<T>(key, value); // Only sets if the key doesn't already existstore.IncrementValue(key); // Thread-safe integer incrementCustom Stores
Section titled “Custom Stores”Implement IKeyValueStore to create your own storage backend:
public class RedisKeyValueStore : IKeyValueStore{ public string Alias => "redis";
public T? Get<T>(string key, T? defaultValue = default) { /* ... */ } public void Set<T>(string key, T value) { /* ... */ } public bool Contains(string key) { /* ... */ } public bool Remove(string key) { /* ... */ } public void Clear() { /* ... */ }}AI Coding Assistant
Section titled “AI Coding Assistant”An AI skill is available for Shiny Stores to help configure key/value stores, persistent service binding, and follow best practices directly in your IDE.
Claude Code
claude plugin add github:shinyorg/skillsGitHub Copilot — Copy the shiny-stores skill file into your repository’s custom instructions.