aemarcoToolboxTypeStore 9.1.7

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

aemarcoToolboxTypeStore

<a href=https://www.nuget.org/packages/aemarcoToolboxTypeStore><img src="https://buildstats.info/nuget/aemarcoToolboxTypeStore"></a><br/>

The aemarcoToolboxTypeStore library provides a robust, flexible, and non-intrusive way to persist single instances of Plain Old CLR Objects (POCOs) to disk. It's ideal for managing application settings, session data, or any small, mutable data structure that needs to be loaded on startup and saved on exit.


Features

  • POCO Persistence: Persist any C# class without modifying its structure with specific attributes or properties.
  • Metadata Smuggling: Automatically injects and extracts persistence-related metadata (timestamps, version) directly into the JSON file, keeping your data models clean.
  • Attribute-Based Configuration: Use attributes on your data classes to easily configure versioning and user-specific data protection.
  • Dependency Injection Integration: Seamlessly integrates with Microsoft.Extensions.DependencyInjection for easy setup and usage.
  • Custom File Paths: Allows types to define custom storage locations, or uses intelligent fallbacks.
  • Save Event Hooks: Provides hooks for pre-save and post-save logic directly on your data models.
  • .NET 8+ & Windows-Specific Protection: Leverages System.Text.Json for efficient serialization and ProtectedData for Windows-specific encryption.

Installation

Install the aemarcoToolboxTypeStore NuGet package into your project:

dotnet add package aemarcoToolboxTypeStore

Setup (Dependency Injection)

The library integrates with Microsoft.Extensions.DependencyInjection. You configure the store once during your application's startup.


using aemarcoCommons.ToolboxTypeStore;


// Basic setup: Uses defaults
services.SetupTypeStore();

// Custom setup:
services.SetupTypeStore(options =>
{
    ...
});

// Custom setup using ServiceProvider:
services.SetupTypeStore((sp, options) =>
{
    ...
});


Defining a Storable Type (T)

For a class to be used with ITypeToFileStore<T>, it must:

  • Be a class (reference type).
  • Have a parameterless constructor (new()).
  • Implement ITypeToFileValue.

Here's an example showcasing custom path, save events, and attribute-based settings:

using aemarcoCommons.ToolboxTypeStore;

[TypeToFileSettings(isUserProtected: true, version: 2)]
public class MyUserSettings : ITypeToFileValue
{
    public string UserName { get; set; } = "DefaultUser";
    public int AppTheme { get; set; } = 0;



    // Optional: Custom File Path !! Should NOT rely on the instance's state.
    public string? GetCustomFilePath() => ...;

    // Optional: Save Event Hooks
    public void OnSaving() => ...;
    public void OnSaved() => ...;
}

Usage

Inject ITypeToFileStore<T> into your services.

using aemarcoCommons.ToolboxTypeStore;

// Retrieve the store
var userSettingsStore = serviceProvider.GetRequiredService<ITypeToFileStore<MyUserSettings>>();

// Access and modify settings
userSettingsStore.Instance.UserName = "NewUser";
userSettingsStore.SaveChanges(); // Explicitly save changes

// Access metadata
Console.WriteLine(
$"First Created: {userSettingsStore.TimestampCreated}, Last Saved: {userSettingsStore.TimestampSaved}");

// Reset to default
userSettingsStore.CommitReset();

// On application exit, the store's Dispose() method is automatically called by the DI container,
// which triggers SaveChanges() if any modifications were made to the Instance.
Product Compatible and additional computed target framework versions.
.NET net8.0-windows7.0 is compatible.  net9.0-windows 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
9.1.7 105 2/15/2026