ktsu.AppDataStorage
1.15.6
Prefix Reserved
Package renamed
See the version list below for details.
dotnet add package ktsu.AppDataStorage --version 1.15.6
NuGet\Install-Package ktsu.AppDataStorage -Version 1.15.6
<PackageReference Include="ktsu.AppDataStorage" Version="1.15.6" />
<PackageVersion Include="ktsu.AppDataStorage" Version="1.15.6" />
<PackageReference Include="ktsu.AppDataStorage" />
paket add ktsu.AppDataStorage --version 1.15.6
#r "nuget: ktsu.AppDataStorage, 1.15.6"
#addin nuget:?package=ktsu.AppDataStorage&version=1.15.6
#tool nuget:?package=ktsu.AppDataStorage&version=1.15.6
ktsu.AppDataStorage
A .NET library for simple application data management with JSON serialization.
Introduction
ktsu.AppDataStorage
is a .NET library designed to simplify the process of managing application data. It facilitates saving and loading configuration or state data to the application's data folder, leveraging JSON serialization. The library handles file operations with safety mechanisms like automatic backups and provides an intuitive API for developers.
Features
- Easy-to-use API: Intuitive methods for saving and loading data.
- Automatic Backup: Backs up original files before overwriting to ensure data safety.
- Custom Serialization Options: Uses
System.Text.Json
with support for custom converters. - File System Abstraction: Uses
System.IO.Abstractions
for easy unit testing and mocking. - Debounced Saves: Prevents frequent file writes to improve performance.
- Support for Multiple Applications: Organizes data by application domain for isolation.
- Static Instance Access: Provides easy access to a singleton-like instance for centralized data management.
Installation
Package Manager Console
Install-Package ktsu.AppDataStorage
.NET CLI
dotnet add package ktsu.AppDataStorage
Package Reference
<PackageReference Include="ktsu.AppDataStorage" Version="x.y.z" />
Usage Examples
Defining Your Application Data Class
Create a class that inherits from AppData<T>
, where T
is your custom data type.
public class MyAppData : AppData<MyAppData>
{
public string Setting1 { get; set; } = "hello";
public int Setting2 { get; set; } = 12;
}
Loading Data
Load existing data or create a new instance if no data file exists using LoadOrCreate
.
var data = MyAppData.LoadOrCreate();
Console.WriteLine(data.Setting1);
Console.WriteLine(data.Setting2);
// Output:
// hello
// 12
Accessing the Static Instance
The AppData<T>
class provides a static instance through the Get
method, which ensures a single, easily accessible instance is available throughout your application:
var data = MyAppData.Get();
Console.WriteLine(data.Setting1);
The static instance is initialized automatically and matches the instance returned by LoadOrCreate
. Changes to the static instance are persistent once saved:
var data = MyAppData.Get();
data.Setting1 = "new value";
data.Save();
var sameData = MyAppData.Get();
Console.WriteLine(sameData.Setting1);
// Output:
// new value
Saving Data
Modify properties and save the data using the Save
method.
var data = MyAppData.Get();
data.Setting1 = "goodbye";
data.Setting2 = 42;
data.Save();
var reloadedData = MyAppData.Get();
Console.WriteLine(reloadedData.Setting1);
Console.WriteLine(reloadedData.Setting2);
// Output:
// goodbye
// 42
Advanced Usage
Queued and Debounced Saving
For scenarios with frequent updates, you can queue save operations using QueueSave
, which automatically debounces writes to avoid frequent file system operations.
MyAppData.QueueSave(); // Schedules a save
MyAppData.SaveIfRequired(); // Performs the save if the debounce threshold is exceeded
Writing and Reading Arbitrary Text Files
Write and read arbitrary files in the application's data folder using the static AppData
class.
Write Text
AppData.WriteText("example.txt".As<FileName>(), "Hello, AppData!");
Read Text
string content = AppData.ReadText("example.txt".As<FileName>());
Console.WriteLine(content);
// Output:
// Hello, AppData!
Customizing Serialization
Serialization behavior can be customized using JsonSerializerOptions
. By default, the library uses:
- Indented JSON for readability.
ReferenceHandler.Preserve
for circular references.- Converters such as
JsonStringEnumConverter
andToStringJsonConverter
.
Directory and File Paths
Data is stored in a directory unique to the current application domain:
var appDataPath = AppData.Path;
Console.WriteLine($"App Data Path: {appDataPath}");
API Reference
AppData
Static Class
The primary static class for working with application data storage.
Properties
Name | Type | Description |
---|---|---|
Path |
AbsoluteDirectoryPath |
The path where persistent data is stored for this application |
Methods
Name | Return Type | Description |
---|---|---|
WriteText<T>(T appData, string text) |
void |
Writes text to an app data file with backup safety |
ReadText<T>(T appData) |
string |
Reads text from an app data file |
QueueSave<T>(this T appData) |
void |
Queues a save operation for the app data |
SaveIfRequired<T>(this T appData) |
void |
Saves the app data if required based on debounce settings |
AppData<T>
Generic Abstract Class
Base class for app data storage implementations.
Properties
Name | Type | Description |
---|---|---|
FilePath |
AbsoluteFilePath |
The file path for the app data file |
Methods
Name | Return Type | Description |
---|---|---|
Get() |
T |
Gets the current instance of the app data |
LoadOrCreate() |
T |
Loads app data from file or creates a new instance |
Save() |
void |
Saves the app data to the file system |
QueueSave() |
void |
Queues a save operation for the current app data instance |
SaveIfRequired() |
void |
Saves the app data if required based on debounce settings |
Contributing
Contributions are welcome! Feel free to open issues or submit pull requests.
License
This project is licensed under the MIT License. See the LICENSE.md file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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. |
-
net9.0
- ktsu.CaseConverter (>= 1.3.2)
- ktsu.StrongPaths (>= 1.3.1)
- ktsu.StrongStrings (>= 1.4.2)
- ktsu.ToStringJsonConverter (>= 1.2.3)
- TestableIO.System.IO.Abstractions (>= 22.0.14)
- TestableIO.System.IO.Abstractions.Wrappers (>= 22.0.14)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on ktsu.AppDataStorage:
Package | Downloads |
---|---|
ktsu.CredentialCache
CredentialCache |
|
ktsu.SingleAppInstance
A .NET library that ensures only one instance of your application is running at a time. |
|
ktsu.GitIntegration
Git Integration |
|
ktsu.BlastMerge
Cross-repository file synchronization tool that uses intelligent iterative merging to unify multiple file versions with interactive conflict resolution. Features include batch processing with custom search paths and exclusion patterns, parallel file hashing for performance, persistent command history, and comprehensive automation capabilities for multi-repository workflows. Supports advanced diff visualization, pattern-based file discovery, and discrete processing phases with real-time progress reporting. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated | |
---|---|---|---|
1.15.7-pre.1 | 349 | 5/22/2025 | |
1.15.6 | 2,007 | 5/22/2025 | |
1.15.5 | 573 | 5/21/2025 | |
1.15.5-pre.1 | 194 | 5/20/2025 | |
1.15.4 | 431 | 5/19/2025 | |
1.15.0 | 514 | 4/29/2025 | |
1.13.0 | 251 | 4/28/2025 | |
1.12.0 | 249 | 4/28/2025 | |
1.11.0 | 268 | 4/27/2025 | |
1.10.0 | 225 | 4/27/2025 | |
1.9.0 | 232 | 4/27/2025 | |
1.8.0 | 182 | 4/26/2025 | |
1.7.3-pre.6 | 133 | 4/26/2025 | |
1.7.3-pre.5 | 135 | 4/25/2025 | |
1.7.3-pre.4 | 194 | 4/25/2025 | |
1.7.3-pre.3 | 200 | 4/21/2025 | |
1.7.3-pre.2 | 205 | 4/10/2025 | |
1.7.3-pre.1 | 207 | 4/7/2025 | |
1.7.2 | 626 | 4/4/2025 | |
1.7.2-pre.1 | 209 | 3/31/2025 | |
1.7.1 | 350 | 3/30/2025 | |
1.7.0 | 754 | 3/30/2025 | |
1.6.0 | 253 | 3/30/2025 | |
1.5.1-pre.8 | 153 | 3/29/2025 | |
1.5.1-pre.7 | 540 | 3/25/2025 | |
1.5.1-pre.6 | 190 | 3/15/2025 | |
1.5.1-pre.5 | 131 | 3/14/2025 | |
1.5.1-pre.4 | 253 | 3/3/2025 | |
1.5.1-pre.3 | 147 | 2/25/2025 | |
1.5.1-pre.2 | 160 | 2/18/2025 | |
1.5.1-pre.1 | 150 | 2/17/2025 | |
1.5.0 | 1,135 | 2/14/2025 | |
1.4.8-pre.3 | 146 | 2/6/2025 | |
1.4.8-pre.2 | 145 | 2/5/2025 | |
1.4.8-pre.1 | 136 | 2/5/2025 | |
1.4.7 | 1,070 | 1/3/2025 | |
1.4.7-pre.27 | 145 | 2/3/2025 | |
1.4.7-pre.26 | 142 | 2/3/2025 | |
1.4.7-pre.25 | 141 | 2/3/2025 | |
1.4.7-pre.24 | 143 | 2/2/2025 | |
1.4.7-pre.23 | 138 | 1/31/2025 | |
1.4.7-pre.22 | 141 | 1/30/2025 | |
1.4.7-pre.21 | 130 | 1/29/2025 | |
1.4.7-pre.20 | 137 | 1/28/2025 | |
1.4.7-pre.19 | 136 | 1/27/2025 | |
1.4.7-pre.18 | 136 | 1/26/2025 | |
1.4.7-pre.17 | 138 | 1/24/2025 | |
1.4.7-pre.16 | 142 | 1/22/2025 | |
1.4.7-pre.15 | 127 | 1/20/2025 | |
1.4.7-pre.14 | 131 | 1/18/2025 | |
1.4.7-pre.13 | 135 | 1/16/2025 | |
1.4.7-pre.12 | 119 | 1/14/2025 | |
1.4.7-pre.11 | 132 | 1/13/2025 | |
1.4.7-pre.10 | 140 | 1/11/2025 | |
1.4.7-pre.9 | 132 | 1/10/2025 | |
1.4.7-pre.8 | 135 | 1/10/2025 | |
1.4.7-pre.7 | 130 | 1/8/2025 | |
1.4.7-pre.6 | 140 | 1/7/2025 | |
1.4.7-pre.5 | 147 | 1/5/2025 | |
1.4.7-pre.4 | 160 | 1/3/2025 | |
1.4.7-pre.3 | 146 | 1/3/2025 | |
1.4.7-pre.2 | 147 | 1/3/2025 | |
1.4.7-pre.1 | 150 | 1/3/2025 | |
1.4.6 | 207 | 1/2/2025 | |
1.4.5 | 200 | 1/2/2025 | |
1.4.4 | 195 | 1/2/2025 | |
1.4.3 | 185 | 1/2/2025 | |
1.4.2 | 192 | 1/2/2025 | |
1.4.1 | 183 | 1/2/2025 | |
1.4.0 | 185 | 1/2/2025 | |
1.3.16 | 490 | 1/2/2025 | |
1.3.16-pre.6 | 151 | 1/2/2025 | |
1.3.16-pre.5 | 163 | 12/31/2024 | |
1.3.16-pre.4 | 138 | 12/30/2024 | |
1.3.16-pre.3 | 139 | 12/29/2024 | |
1.3.16-pre.2 | 143 | 12/28/2024 | |
1.3.16-pre.1 | 136 | 12/27/2024 | |
1.3.15 | 292 | 12/27/2024 | |
1.3.14 | 178 | 12/27/2024 | |
1.3.13-pre.1 | 142 | 12/27/2024 | |
1.3.12-pre.1 | 140 | 12/27/2024 | |
1.3.11-pre.1 | 141 | 12/27/2024 | |
1.3.10 | 220 | 12/26/2024 | |
1.3.10-pre.1 | 138 | 12/27/2024 | |
1.3.9 | 219 | 12/26/2024 | |
1.3.8 | 180 | 12/26/2024 | |
1.3.7 | 173 | 12/26/2024 | |
1.3.6 | 174 | 12/26/2024 | |
1.3.5 | 182 | 12/26/2024 | |
1.3.4 | 188 | 12/26/2024 | |
1.3.3 | 234 | 12/25/2024 | |
1.3.2 | 340 | 12/23/2024 | |
1.3.1 | 204 | 12/23/2024 | |
1.3.0 | 174 | 12/23/2024 | |
1.2.4 | 175 | 12/23/2024 | |
1.2.3 | 229 | 12/22/2024 | |
1.2.2 | 180 | 12/22/2024 | |
1.2.1 | 200 | 12/22/2024 | |
1.2.0 | 182 | 12/22/2024 | |
1.1.57 | 238 | 12/19/2024 | |
1.1.56 | 228 | 12/19/2024 | |
1.1.55 | 256 | 12/17/2024 | |
1.1.54 | 231 | 12/16/2024 | |
1.1.53 | 367 | 12/9/2024 | |
1.1.52 | 267 | 12/6/2024 | |
1.1.51 | 273 | 12/5/2024 | |
1.1.50 | 210 | 12/5/2024 | |
1.1.49 | 221 | 12/4/2024 | |
1.1.48 | 263 | 12/2/2024 | |
1.1.47 | 183 | 12/2/2024 | |
1.1.46 | 201 | 12/2/2024 | |
1.1.45 | 193 | 12/2/2024 | |
1.1.44 | 193 | 12/2/2024 | |
1.1.43 | 205 | 12/1/2024 | |
1.1.42 | 187 | 12/1/2024 | |
1.1.41 | 262 | 12/1/2024 | |
1.1.40 | 194 | 12/1/2024 | |
1.1.39 | 229 | 11/30/2024 | |
1.1.38 | 190 | 11/30/2024 | |
1.1.37 | 207 | 11/29/2024 | |
1.1.36 | 226 | 11/28/2024 | |
1.1.35 | 233 | 11/27/2024 | |
1.1.34 | 226 | 11/26/2024 | |
1.1.33 | 327 | 11/20/2024 | |
1.1.32 | 223 | 11/19/2024 | |
1.1.31 | 251 | 11/15/2024 | |
1.1.30 | 211 | 11/14/2024 | |
1.1.29 | 232 | 11/13/2024 | |
1.1.28 | 221 | 11/12/2024 | |
1.1.27 | 239 | 11/11/2024 | |
1.1.26 | 239 | 11/8/2024 | |
1.1.25 | 229 | 11/6/2024 | |
1.1.24 | 223 | 11/5/2024 | |
1.1.23 | 233 | 11/4/2024 | |
1.1.22 | 333 | 11/2/2024 | |
1.1.21 | 196 | 11/1/2024 | |
1.1.20 | 478 | 10/18/2024 | |
1.1.19 | 419 | 10/9/2024 | |
1.1.18 | 207 | 10/8/2024 | |
1.1.17 | 187 | 10/7/2024 | |
1.1.16 | 205 | 10/4/2024 | |
1.1.15 | 299 | 9/25/2024 | |
1.1.14 | 214 | 9/24/2024 | |
1.1.13 | 199 | 9/23/2024 | |
1.1.12 | 215 | 9/20/2024 | |
1.1.11 | 214 | 9/19/2024 | |
1.1.10 | 204 | 9/19/2024 | |
1.1.9 | 176 | 9/19/2024 | |
1.1.8 | 213 | 9/19/2024 | |
1.1.7 | 250 | 9/18/2024 | |
1.1.6 | 205 | 9/18/2024 | |
1.1.5 | 193 | 9/18/2024 | |
1.1.4 | 203 | 9/18/2024 | |
1.1.3 | 250 | 9/14/2024 | |
1.1.2 | 217 | 9/14/2024 |
## v1.15.6
Initial release or repository with no prior history.