SetNet.Persistence 1.2.0

dotnet add package SetNet.Persistence --version 1.2.0
                    
NuGet\Install-Package SetNet.Persistence -Version 1.2.0
                    
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="SetNet.Persistence" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SetNet.Persistence" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="SetNet.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 SetNet.Persistence --version 1.2.0
                    
#r "nuget: SetNet.Persistence, 1.2.0"
                    
#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 SetNet.Persistence@1.2.0
                    
#: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=SetNet.Persistence&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=SetNet.Persistence&version=1.2.0
                    
Install as a Cake Tool

<p align="center"> <img src="https://raw.githubusercontent.com/Povstalez/SetNet/master/assets/icon.png" alt="SetNet" width="96"> </p>

SetNet.Persistence

A durable-state seam for SetNet module stores — one interface, in-memory or JSON-file out of the box, your Redis/DB behind the same shape.

Most SetNet modules keep their state (inventories, wallets, progression, mail queues, save-games) behind a small store interface that defaults to an in-process dictionary. This package gives those seams something durable: IDocumentStore<T> for keyed values and ISnapshotStore for opaque blobs, each with a memory implementation for tests and a file implementation for dev — swap in a Redis/DB store later without touching callers. No wire protocol; pure storage.

Install

dotnet add package SetNet
dotnet add package SetNet.Persistence

Usage

// keyed documents — get/set/remove/enumerate by key
IDocumentStore<PlayerSave> saves = new JsonFileDocumentStore<PlayerSave>("data/saves.json");
await saves.SetAsync(playerKey, new PlayerSave { Level = 12, Gold = 500 });
PlayerSave? save = await saves.GetAsync(playerKey);
IReadOnlyList<string> keys = await saves.KeysAsync();

// opaque blobs — world snapshots, serialized module state
ISnapshotStore snaps = new FileSnapshotStore("data/snapshots");
await snaps.SaveAsync("world", worldBytes);
byte[]? bytes = await snaps.LoadAsync("world");

// tests / single-node: in-process, non-durable
IDocumentStore<PlayerSave> mem = new MemoryDocumentStore<PlayerSave>();

API

Documents: IDocumentStore<T> — GetAsync, SetAsync, RemoveAsync, ExistsAsync, KeysAsync, AllAsync. Implementations: MemoryDocumentStore<T>, JsonFileDocumentStore<T>(path, JsonSerializerOptions?). Snapshots: ISnapshotStore — SaveAsync, LoadAsync, DeleteAsync. Implementations: MemorySnapshotStore, FileSnapshotStore(directory).

Notes

  • A seam, not a hub. There's no UseX() and no Runtime.Enable() — this is plumbing. Pass one of these stores wherever a module accepts its store interface, or implement the module's own store interface on top of an IDocumentStore<T>.
  • Memory for tests, file for dev, your own at scale. MemoryDocumentStore<T>/MemorySnapshotStore are in-process and non-durable. JsonFileDocumentStore<T> keeps a single human-readable key → value map, loaded on construction and rewritten (via a temp-file swap) on every mutation — great for small/medium data; move to a database at scale. FileSnapshotStore writes one <name>.snapshot file per blob.
  • Thread-safe. The file document store guards reads and writes with a lock; the memory stores use ConcurrentDictionary.
  • System.Text.Json. JsonFileDocumentStore<T> serializes with System.Text.Json (WriteIndented by default) — pass your own JsonSerializerOptions to control naming, converters, etc. Make sure T is round-trippable.

Documentation & source

License

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on SetNet.Persistence:

Package Downloads
SetNet.Accounts

Account store + authentication for SetNet: a generic AccountServer<TAccount> over any IDocumentStore (memory/file/SQL/Mongo). Register/authenticate with a pluggable password hasher (PBKDF2 default), ban/unban, change password. Subclass AccountBase (or use its Extra bag) to add ANY custom fields with no schema change. Pairs with SetNet.LoginServer. Depends on SetNet + SetNet.Persistence.

SetNet.Persistence.EfCore

Entity Framework Core-backed IDocumentStore<T> / ISnapshotStore for SetNet.Persistence. Provider-agnostic — pass DbContextOptions configured for SQLite / PostgreSQL / SQL Server / etc. Each value is stored as JSON in a key/value table, so custom fields need no schema change. Depends on SetNet.Persistence + Microsoft.EntityFrameworkCore(.Relational).

SetNet.Persistence.Postgres

PostgreSQL-backed IDocumentStore<T> / ISnapshotStore for SetNet.Persistence via Npgsql. Each value is stored in a JSONB column, so custom fields need no schema change AND stay queryable/indexable in SQL (e.g. WHERE doc->>'vipUntil' > now()). Native upsert (INSERT … ON CONFLICT). Depends on SetNet.Persistence + Npgsql.

SetNet.Persistence.MongoDB

MongoDB-backed IDocumentStore<T> / ISnapshotStore for SetNet.Persistence via MongoDB.Driver. Each value is stored as a native BSON document, so custom fields need no schema change AND stay queryable/indexable in Mongo. Upsert via ReplaceOne(IsUpsert). Depends on SetNet.Persistence + MongoDB.Driver.

SetNet.Persistence.Dapper

Dapper-backed IDocumentStore<T> / ISnapshotStore for SetNet.Persistence: store any POCO as JSON in a key/value table on any ADO.NET database (SQLite, PostgreSQL, MySQL, SQL Server, …). Custom fields need no schema change — the whole object is serialized. Portable upsert (delete+insert in a transaction). Depends on SetNet.Persistence + Dapper.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 293 8/5/2026