Fluxor.Persistence
1.0.9
dotnet add package Fluxor.Persistence --version 1.0.9
NuGet\Install-Package Fluxor.Persistence -Version 1.0.9
<PackageReference Include="Fluxor.Persistence" Version="1.0.9" />
<PackageVersion Include="Fluxor.Persistence" Version="1.0.9" />
<PackageReference Include="Fluxor.Persistence" />
paket add Fluxor.Persistence --version 1.0.9
#r "nuget: Fluxor.Persistence, 1.0.9"
#:package Fluxor.Persistence@1.0.9
#addin nuget:?package=Fluxor.Persistence&version=1.0.9
#tool nuget:?package=Fluxor.Persistence&version=1.0.9
Fluxor.Persistence
Fluxor.Persistence is a seamless extension to Fluxor that introduces state persistence. It allows you to save and restore your application's state using your preferred storage mechanism.
Getting Started
Installation
You can install the package via NuGet:
dotnet add package Fluxor.Persistence
Configuration
Integrate the persistence mechanism into your project by configuring Fluxor in your Program.cs
:
builder.Services.AddFluxor(options =>
{
options.ScanAssemblies(typeof(Program).Assembly);
options.UsePersist(cfg =>
{
cfg.ForState<CounterState>().AddFullStatePersistence();
cfg.ForState<WeatherState>()
.AddPropertyPersistence(x => x.SelectedCity)
.AddPropertyPersistence(x => x.TemperatureUnit);
});
});
Handling Nested Properties
Fluxor.Persistence also supports nested properties. Here's how you can configure it:
cfg.ForState<UserSettings>()
.AddPropertyPersistence(x => x.Theme.Colours.Pallette)
.AddPropertyPersistence(x => x.Theme.IsDarkTheme);
Custom Persistence Service
By default, the extension uses Blazored.LocalStorage for storing state. If you need a different storage solution, implement the IPersistenceService
interface:
internal sealed class InMemoryPersistenceService : IPersistenceService
{
private readonly ConcurrentDictionary<string, string> _storage = new();
public ValueTask<string?> GetItemAsStringAsync(string storageKey)
{
_storage.TryGetValue(storageKey, out var value);
return ValueTask.FromResult<string?>(value);
}
public ValueTask SetItemAsStringAsync(string storageKey, string value)
{
_storage[storageKey] = value;
return ValueTask.CompletedTask;
}
}
Then, register your custom service:
builder.Services.AddScoped<IPersistenceService, InMemoryPersistenceService>();
Examples
For practical implementations, check out the Blazor WASM example:
- Blazor WASM Example: FluxorPersistence.Blazor.Wasm
Demonstration
Check out the following GIF to see state persistence in action within a Blazor WASM application:
Contributing
Contributions are welcome! Feel free to open issues or submit pull requests for improvements and new features.
Publishing a New Version
To publish a new version of the library to the NuGet registry create a new release in the GitHub repository, the release
event will automatically publish the package.
License
This project is licensed under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Blazored.LocalStorage (>= 4.5.0)
- Fluxor (>= 6.5.2)
-
net9.0
- Blazored.LocalStorage (>= 4.5.0)
- Fluxor (>= 6.5.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.9 | 850 | 3/23/2025 |
1.0.7 | 1,725 | 1/15/2025 |
1.0.5-g7e021a6b81 | 74 | 1/15/2025 |
1.0.3-g726f53a66d | 79 | 1/15/2025 |