Fluxor.Persistence 1.0.9

dotnet add package Fluxor.Persistence --version 1.0.9
                    
NuGet\Install-Package Fluxor.Persistence -Version 1.0.9
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Fluxor.Persistence" Version="1.0.9" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Fluxor.Persistence" Version="1.0.9" />
                    
Directory.Packages.props
<PackageReference Include="Fluxor.Persistence" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Fluxor.Persistence --version 1.0.9
                    
#r "nuget: Fluxor.Persistence, 1.0.9"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Fluxor.Persistence@1.0.9
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Fluxor.Persistence&version=1.0.9
                    
Install as a Cake Addin
#tool nuget:?package=Fluxor.Persistence&version=1.0.9
                    
Install as a Cake Tool

Fluxor.Persistence

Logo

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.

dotnet build

Technical Debt Quality Gate Status Reliability Rating Duplicated Lines (%) Vulnerabilities Bugs Security Rating Maintainability Rating Code Smells Lines of Code

Getting Started

Installation

You can install the package via NuGet:

dotnet add package Fluxor.Persistence

NuGet version (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:

Demonstration

Check out the following GIF to see state persistence in action within a Blazor WASM application:

Persistence Demo

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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