DropBear.Codex.StateManagement
2024.5.7
See the version list below for details.
dotnet add package DropBear.Codex.StateManagement --version 2024.5.7
NuGet\Install-Package DropBear.Codex.StateManagement -Version 2024.5.7
<PackageReference Include="DropBear.Codex.StateManagement" Version="2024.5.7" />
paket add DropBear.Codex.StateManagement --version 2024.5.7
#r "nuget: DropBear.Codex.StateManagement, 2024.5.7"
// Install DropBear.Codex.StateManagement as a Cake Addin #addin nuget:?package=DropBear.Codex.StateManagement&version=2024.5.7 // Install DropBear.Codex.StateManagement as a Cake Tool #tool nuget:?package=DropBear.Codex.StateManagement&version=2024.5.7
StateSnapshotManager Library
Overview
The StateSnapshotManager
library provides a comprehensive solution for managing state snapshots in .NET applications. It supports automatic snapshotting, state reversion, and notifications upon state changes, making it ideal for applications that require historical state management or undo capabilities.
Features
- Automatic Snapshotting: Automatically captures snapshots of your application's state at configured intervals.
- State Reversion: Allows reverting to any previously captured state snapshot.
- Observable State Changes: Utilizes the R3 library to notify subscribers about state reversions, enabling reactive programming scenarios.
- Flexible Configuration: Use the
SnapshotBuilder
for easy and fluent configuration of snapshot managers. - Multi-Model Management: Manage snapshots for multiple models using the
SnapshotManagerRegistry
.
Getting Started
Installation
To install the StateSnapshotManager
library, use the following NuGet command:
Install-Package DropBear.Codex.StateManagement
Usage
Here's a quick example to get you started with a basic snapshot manager:
using DropBear.Codex.StateManagement.StateSnapshots;
public class YourApplication
{
public void Setup()
{
var snapshotManager = new StateSnapshotManager<MyStateType>(true, TimeSpan.FromMinutes(5), TimeSpan.FromDays(1));
snapshotManager.StateReverted.Subscribe(state =>
{
Console.WriteLine("State has been reverted.");
});
// Assume `currentState` is an instance of `MyStateType`
snapshotManager.CreateSnapshot(currentState);
}
}
Using the SnapshotBuilder
Here’s how to use the SnapshotBuilder
to create a configured StateSnapshotManager
:
var builder = new SnapshotBuilder<MyStateType>()
.SetAutomaticSnapshotting(true)
.SetSnapshotInterval(TimeSpan.FromMinutes(10))
.SetRetentionTime(TimeSpan.FromDays(7));
var manager = builder.Build();
Using the SnapshotManagerRegistry
To manage multiple types of snapshot managers:
var registry = new SnapshotManagerRegistry();
registry.CreateSnapshot("userManager", new User { Name = "Alice", Age = 30 });
registry.CreateSnapshot("productManager", new Product { Name = "Widget", Price = 19.99 });
// Reverting state for a user manager
var result = registry.RevertToSnapshot<User>("userManager", 1);
Configuration
StateSnapshotManager
can be configured with the following parameters:
automaticSnapshotting
: Whether the manager should automatically take snapshots.snapshotInterval
: The time interval between automatic snapshots.retentionTime
: How long snapshots should be retained before being discarded.
Building and Contributing
Contributions to the library are welcome! To build the project from source, clone the repository and open it in your preferred .NET development environment.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For support and further assistance, contact the package maintainer or submit an issue on the GitHub repository.
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. |
-
net8.0
- DropBear.Codex.AppLogger (>= 2024.4.14)
- DropBear.Codex.Core (>= 2024.5.6)
- Newtonsoft.Json (>= 13.0.3)
- R3 (>= 1.1.11)
- Stateless (>= 5.15.0)
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 |
---|---|---|
2024.11.5 | 80 | 11/12/2024 |
2024.9.44 | 107 | 9/20/2024 |
2024.9.43 | 108 | 9/16/2024 |
2024.9.42 | 104 | 9/16/2024 |
2024.9.32 | 103 | 9/13/2024 |
2024.9.25 | 103 | 9/11/2024 |
2024.9.1 | 110 | 9/8/2024 |
2024.8.54 | 100 | 9/6/2024 |
2024.8.36 | 103 | 9/2/2024 |
2024.7.1 | 99 | 7/24/2024 |
2024.5.9 | 111 | 5/14/2024 |
2024.5.8 | 117 | 5/14/2024 |
2024.5.7 | 128 | 5/4/2024 |
2024.5.6 | 118 | 5/4/2024 |
2024.5.4 | 116 | 5/4/2024 |
2024.5.3 | 140 | 5/4/2024 |
2024.5.2 | 76 | 5/3/2024 |
2024.5.1 | 75 | 5/3/2024 |
2024.4.44 | 65 | 5/3/2024 |
2024.4.41 | 78 | 5/3/2024 |
2024.4.37 | 83 | 5/3/2024 |
2024.4.36 | 76 | 5/3/2024 |
2024.4.34 | 101 | 5/1/2024 |
2024.4.32 | 107 | 4/30/2024 |
2024.4.31 | 105 | 4/30/2024 |
2024.4.30 | 107 | 4/30/2024 |
2024.4.29 | 109 | 4/30/2024 |
2024.4.27 | 112 | 4/30/2024 |
2024.4.25 | 111 | 4/30/2024 |
2024.4.24 | 106 | 4/30/2024 |
2024.4.23 | 106 | 4/30/2024 |
2024.4.22 | 115 | 4/30/2024 |
2024.4.21 | 112 | 4/30/2024 |
2024.4.20 | 113 | 4/30/2024 |
2024.4.19 | 115 | 4/30/2024 |
2024.4.16 | 97 | 4/29/2024 |
2024.4.14 | 104 | 4/29/2024 |
2024.4.13 | 102 | 4/28/2024 |
2024.4.12 | 101 | 4/28/2024 |
2024.4.10 | 107 | 4/28/2024 |
2024.4.7 | 116 | 4/26/2024 |
2024.4.6 | 114 | 4/25/2024 |
2024.4.5 | 116 | 4/19/2024 |
2024.4.3 | 119 | 4/19/2024 |
2024.4.2 | 126 | 4/16/2024 |
2024.3.6 | 221 | 3/29/2024 |
2024.3.5 | 119 | 3/21/2024 |
2024.3.4 | 124 | 3/17/2024 |
2024.3.3 | 134 | 3/17/2024 |