SoftwareDriven.Persistence 3.2.0

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

SoftwareDriven.Persistence

A .NET persistence abstraction library providing a unified interface for different data storage backends. Targets net10.0.

Installation

dotnet add package SoftwareDriven.Persistence

Core Interfaces

Interface Purpose
IPersistenceModel Base model interface requiring string? Id
IBasicPersistenceProvider<T> CRUD operations, expression-based querying, pagination
IPersistenceProvider<T> Extended: nested collection projections, element match, file storage
IDatabaseManager Provider factory and table name registry

Built-in: FileSystem Provider

The core package includes a JSON file-based provider for simple scenarios.

services.AddSingleton(new JsonSerializerOptions());
services.AddSingleton<FileSystemManager>();
services.AddSingleton<FileSystemDataProvider<MyModel>>();

File Storage

Providers implementing IPersistenceProvider<T> also store binary files via IFileProvider (StoreFile, LoadFile, DeleteFile, FileExists). The backend used for those files is independent of the backend storing the models and is chosen by registering an IFileProviderFactory:

// Local file system (default for FileSystem and MongoDb)
services.AddLocalFileStorage();

// S3 bucket instead - the models stay in MongoDB, the files go to S3
services.AddS3("Files");
services.AddS3FileStorage(managerKey: "Files");

A factory registered under the service key of a persistence provider takes precedence over an unkeyed registration. Without any registration each provider keeps its own default: the local file system for FileSystemDataProvider and MongoDbRepositoryProvider, the bucket for S3RepositoryProvider and the database for IndexedDbRepositoryProvider.

The implementation can also be exchanged per instance at runtime:

provider.FileProvider = new S3FileProvider(s3Manager, logger);
Implementation Package Storage
LocalFileProvider Core {BasePath}/{FileFolder}/{fileId} in the local file system
S3FileProvider S3 {BasePath}/files/{FileFolder}/{fileId} in the bucket
IndexedDbFileProvider IndexedDb the _files_{FileFolder} object store

Provider Packages

Package Backend
SoftwareDriven.Persistence.MongoDb MongoDB
SoftwareDriven.Persistence.Cassandra Apache Cassandra
SoftwareDriven.Persistence.EF.SQLite Entity Framework Core / SQLite
SoftwareDriven.Persistence.IndexedDb Browser IndexedDB (Blazor)

Usage

All providers implement the same interfaces, allowing backend-agnostic code:

public class MyService
{
    private readonly IBasicPersistenceProvider<MyModel> provider;

    public MyService(IBasicPersistenceProvider<MyModel> provider)
    {
        this.provider = provider;
    }

    public async Task Example()
    {
        // Create
        await provider.CreateOrUpdate(new MyModel { Title = "Hello" });

        // Query with expressions
        var results = await provider.FindByExpression(x => x.Title == "Hello");

        // Paginate
        var page = await provider.GetAll(new PaginationOptions<MyModel>
        {
            PageSize = 10,
            PageNumber = 0
        });
    }
}

Maintenance

Deleting entries does not necessarily return their storage to the file system. IDatabaseManager therefore offers maintenance on the database as a whole, independent of a single entity:

if (!databaseManager.SupportsMaintenance)
    return;

var statistics = await databaseManager.GetStatistics();
// statistics.TotalBytes        - what the database occupies
// statistics.ReclaimableBytes  - occupied without being used
// statistics.IsAvailable       - whether the figures could be determined

var result = await databaseManager.Compact();
// result.Success, result.BytesBefore, result.BytesAfter, result.Error

Query SupportsMaintenance instead of switching on DatabaseType. Backends without a maintenance concept report false, unavailable statistics and a CompactResult with Success = false and an explanatory Error.

Backend SupportsMaintenance Operation
EF.SQLite true VACUUM plus PRAGMA wal_checkpoint(TRUNCATE)
MongoDb true (when connected) compact per collection, figures from dbStats
Cassandra false compaction is a matter of the server and nodetool
FileSystem false deleted entries vanish with their file
IndexedDb false the browser manages the storage itself

Models

Inherit from PersistenceModelBase or implement IPersistenceModel:

public class MyModel : PersistenceModelBase
{
    public string Title { get; set; } = "";
    public bool IsActive { get; set; }
}

License

MIT

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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 (5)

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

Package Downloads
SoftwareDriven.Persistence.MongoDb

SoftwareDriven.Persistence.MongoDb is a library with a persistence layer for MongoDb building on top of SoftwareDriven.Persistence.

SoftwareDriven.Persistence.Cassandra

SoftwareDriven.Persistence.Cassandra is a library with a persistence layer for Apache Cassandra building on top of SoftwareDriven.Persistence. Includes DataStax C# Driver for Apache Cassandra v3.19.1 with modifications.

SoftwareDriven.Persistence.EF.SQLite

SoftwareDriven.Persistence.EF.SQLite is a library with a persistence layer for EntityFramework SQLite building on top of SoftwareDriven.Persistence.

SoftwareDriven.Persistence.IndexedDb

SoftwareDriven.Persistence.IndexedDb is a library with a persistence layer for browser IndexedDB building on top of SoftwareDriven.Persistence.

SoftwareDriven.Persistence.S3

SoftwareDriven.Persistence.S3 is a library with a persistence layer for S3-compatible object storage building on top of SoftwareDriven.Persistence.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.2.0 117 9/8/2026
3.1.0 131 8/25/2026
3.0.5 682 4/2/2026
3.0.4 248 2/12/2026
3.0.3 442 2/11/2026
3.0.2 145 2/11/2026
3.0.1 155 2/11/2026
3.0.0 237 2/1/2026
2.12.0 233 1/8/2026
2.9.1 534 4/24/2025
2.9.0 962 11/30/2024
2.8.2 304 11/18/2024
2.8.1 665 7/19/2024
2.8.0 450 7/7/2024
2.7.3 254 11/18/2024
2.7.2 283 6/30/2024
2.7.0 1,153 11/27/2023
2.6.1 1,067 7/25/2023
2.6.0 846 7/23/2023
Loading failed