{"id":28928194,"url":"https://github.com/ktsu-dev/persistenceprovider","last_synced_at":"2026-02-14T03:31:33.408Z","repository":{"id":299763203,"uuid":"1004104076","full_name":"ktsu-dev/PersistenceProvider","owner":"ktsu-dev","description":null,"archived":false,"fork":false,"pushed_at":"2025-06-18T06:04:31.000Z","size":61,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-18T07:21:22.504Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ktsu-dev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.md","dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-18T06:02:24.000Z","updated_at":"2025-06-18T06:05:15.000Z","dependencies_parsed_at":"2025-06-18T07:32:27.430Z","dependency_job_id":null,"html_url":"https://github.com/ktsu-dev/PersistenceProvider","commit_stats":null,"previous_names":["ktsu-dev/persistenceprovider"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ktsu-dev/PersistenceProvider","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FPersistenceProvider","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FPersistenceProvider/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FPersistenceProvider/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FPersistenceProvider/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ktsu-dev","download_url":"https://codeload.github.com/ktsu-dev/PersistenceProvider/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FPersistenceProvider/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278565503,"owners_count":26007757,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-22T14:12:26.564Z","updated_at":"2025-10-06T05:53:02.688Z","avatar_url":"https://github.com/ktsu-dev.png","language":"PowerShell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ktsu.PersistenceProvider\n\nA generic persistence provider library that supports multiple storage backends for .NET applications. This library is designed to complement and integrate with ktsu.SerializationProvider and ktsu.FileSystemProvider libraries, providing a clean abstraction layer for data persistence with dependency injection support.\n\n## Features\n\n- **Multiple Storage Backends**: Memory, file system, application data, and temporary storage\n- **Dependency Injection Ready**: Designed for use with DI containers\n- **Async/Await Support**: All operations are asynchronous\n- **Generic Key Support**: Use any type as a key (string, Guid, int, etc.)\n- **Serialization Integration**: Works with any ktsu.SerializationProvider implementation\n- **File System Integration**: Leverages ktsu.FileSystemProvider for file operations\n- **Thread-Safe**: Concurrent operations are handled safely\n\n## Installation\n\n```bash\n# Install from NuGet\ndotnet add package ktsu.PersistenceProvider\n```\n\n## Quick Start\n\n### Basic Usage with Memory Provider\n\n```csharp\nusing ktsu.PersistenceProvider;\nusing ktsu.SerializationProvider;\n\n// Create a serialization provider (implementation not shown)\nISerializationProvider serializer = new JsonSerializationProvider(); // or any other implementation\n\n// Create a memory-based persistence provider\nIPersistenceProvider\u003cstring\u003e provider = new MemoryPersistenceProvider\u003cstring\u003e(serializer);\n\n// Store an object\nawait provider.StoreAsync(\"user:123\", new UserSettings \n{ \n    Theme = \"Dark\", \n    Language = \"en-US\" \n});\n\n// Retrieve the object\nvar settings = await provider.RetrieveAsync\u003cUserSettings\u003e(\"user:123\");\n\n// Check if an object exists\nbool exists = await provider.ExistsAsync(\"user:123\");\n\n// Remove an object\nawait provider.RemoveAsync(\"user:123\");\n```\n\n### File System Provider\n\n```csharp\nusing ktsu.PersistenceProvider;\nusing ktsu.FileSystemProvider;\nusing ktsu.SerializationProvider;\n\n// Create providers\nIFileSystemProvider fileSystem = new FileSystemProvider(); // or any other implementation\nISerializationProvider serializer = new JsonSerializationProvider();\n\n// Create file system-based persistence provider\nIPersistenceProvider\u003cstring\u003e provider = new FileSystemPersistenceProvider\u003cstring\u003e(\n    fileSystem, \n    serializer, \n    @\"C:\\MyApp\\Data\");\n\n// Use same interface as memory provider\nawait provider.StoreAsync(\"config\", new AppConfig { Version = \"1.0\" });\nvar config = await provider.RetrieveAsync\u003cAppConfig\u003e(\"config\");\n```\n\n### AppData Provider\n\n```csharp\nusing ktsu.PersistenceProvider;\nusing ktsu.FileSystemProvider;\nusing ktsu.SerializationProvider;\n\n// Create providers\nIFileSystemProvider fileSystem = new FileSystemProvider();\nISerializationProvider serializer = new JsonSerializationProvider();\n\n// Create AppData-based persistence provider (stores in %APPDATA%\\MyApp)\nIPersistenceProvider\u003cstring\u003e provider = new AppDataPersistenceProvider\u003cstring\u003e(\n    fileSystem, \n    serializer, \n    \"MyApp\");\n\n// With optional subdirectory (stores in %APPDATA%\\MyApp\\Settings)\nIPersistenceProvider\u003cstring\u003e providerWithSubdir = new AppDataPersistenceProvider\u003cstring\u003e(\n    fileSystem, \n    serializer, \n    \"MyApp\", \n    \"Settings\");\n\n// Store application data\nawait provider.StoreAsync(\"preferences\", new UserPreferences \n{ \n    AutoSave = true,\n    CheckForUpdates = false \n});\n```\n\n### Temporary Storage Provider\n\n```csharp\nusing ktsu.PersistenceProvider;\nusing ktsu.FileSystemProvider;\nusing ktsu.SerializationProvider;\n\n// Create temporary storage provider\nIPersistenceProvider\u003cGuid\u003e provider = new TempPersistenceProvider\u003cGuid\u003e(\n    fileSystemProvider, \n    serializationProvider, \n    \"MyApp\");\n\n// Store temporary data\nGuid sessionId = Guid.NewGuid();\nawait provider.StoreAsync(sessionId, new SessionData { StartTime = DateTime.UtcNow });\n\n// Clean up on dispose\nusing var tempProvider = provider as TempPersistenceProvider\u003cGuid\u003e;\ntempProvider?.Dispose(cleanupDirectory: true);\n```\n\n## Dependency Injection\n\nRegister persistence providers in your DI container:\n\n```csharp\nusing Microsoft.Extensions.DependencyInjection;\n\nvar services = new ServiceCollection();\n\n// Register dependencies\nservices.AddSingleton\u003cISerializationProvider, JsonSerializationProvider\u003e();\nservices.AddSingleton\u003cIFileSystemProvider, FileSystemProvider\u003e();\n\n// Register persistence providers\nservices.AddSingleton\u003cIPersistenceProvider\u003cstring\u003e\u003e(provider =\u003e\n    new MemoryPersistenceProvider\u003cstring\u003e(\n        provider.GetRequiredService\u003cISerializationProvider\u003e()));\n\nservices.AddSingleton\u003cIPersistenceProvider\u003cGuid\u003e\u003e(provider =\u003e\n    new FileSystemPersistenceProvider\u003cGuid\u003e(\n        provider.GetRequiredService\u003cIFileSystemProvider\u003e(),\n        provider.GetRequiredService\u003cISerializationProvider\u003e(),\n        @\"C:\\MyApp\\Data\"));\n\n// Register AppData provider\nservices.AddSingleton\u003cIPersistenceProvider\u003cstring\u003e\u003e(provider =\u003e\n    new AppDataPersistenceProvider\u003cstring\u003e(\n        provider.GetRequiredService\u003cIFileSystemProvider\u003e(),\n        provider.GetRequiredService\u003cISerializationProvider\u003e(),\n        \"MyApp\"));\n\n// Use in your services\nservices.AddTransient\u003cIUserService, UserService\u003e();\n```\n\n## Available Providers\n\n### MemoryPersistenceProvider\u003cTKey\u003e\n- **Storage**: In-memory dictionary\n- **Persistence**: No (data lost on application exit)\n- **Use Case**: Caching, temporary data, testing\n- **Thread Safety**: Yes (ConcurrentDictionary)\n\n### FileSystemPersistenceProvider\u003cTKey\u003e\n- **Storage**: File system as JSON files\n- **Persistence**: Yes (survives application restart)\n- **Use Case**: Configuration files, user data, application state\n- **Thread Safety**: Yes (atomic file operations)\n\n### AppDataPersistenceProvider\u003cTKey\u003e\n- **Storage**: Application data directory (%APPDATA%\\ApplicationName on Windows)\n- **Persistence**: Yes (survives application restart)\n- **Use Case**: User-specific application data, settings, preferences\n- **Thread Safety**: Yes (atomic file operations)\n\n### TempPersistenceProvider\u003cTKey\u003e\n- **Storage**: System temporary directory\n- **Persistence**: Limited (may be cleaned up by system)\n- **Use Case**: Temporary files, cache, session data\n- **Thread Safety**: Yes (atomic file operations)\n\n## Interface\n\n```csharp\npublic interface IPersistenceProvider\u003cTKey\u003e where TKey : notnull\n{\n    string ProviderName { get; }\n    bool IsPersistent { get; }\n    \n    Task StoreAsync\u003cT\u003e(TKey key, T obj, CancellationToken cancellationToken = default);\n    Task\u003cT?\u003e RetrieveAsync\u003cT\u003e(TKey key, CancellationToken cancellationToken = default);\n    Task\u003cT\u003e RetrieveOrCreateAsync\u003cT\u003e(TKey key, CancellationToken cancellationToken = default) where T : new();\n    Task\u003cbool\u003e ExistsAsync(TKey key, CancellationToken cancellationToken = default);\n    Task\u003cbool\u003e RemoveAsync(TKey key, CancellationToken cancellationToken = default);\n    Task\u003cIEnumerable\u003cTKey\u003e\u003e GetAllKeysAsync(CancellationToken cancellationToken = default);\n    Task ClearAsync(CancellationToken cancellationToken = default);\n}\n```\n\n## Error Handling\n\nAll providers throw `PersistenceProviderException` for operation failures:\n\n```csharp\ntry \n{\n    await provider.StoreAsync(\"key\", data);\n}\ncatch (PersistenceProviderException ex)\n{\n    // Handle persistence-specific errors\n    Console.WriteLine($\"Storage failed: {ex.Message}\");\n}\n```\n\n## Integration with Other Libraries\n\nThis library is designed to work with:\n\n- **ktsu.SerializationProvider**: For object serialization/deserialization\n- **ktsu.FileSystemProvider**: For file system operations with testing support\n- **Any DI Container**: Microsoft.Extensions.DependencyInjection, Autofac, etc.\n\n## Building\n\n```bash\ndotnet build PersistenceProvider.sln\n```\n\n## Testing\n\n```bash\ndotnet test PersistenceProvider.sln\n```\n\n## Contributing\n\nThis library follows the same patterns and conventions as other ktsu.dev libraries. Please ensure:\n\n- All public APIs are documented with XML comments\n- Code follows established patterns from SerializationProvider and FileSystemProvider\n- Tests are included for new functionality\n- Changes are backward compatible\n\n## License\n\nMIT License - see LICENSE file for details. ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktsu-dev%2Fpersistenceprovider","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fktsu-dev%2Fpersistenceprovider","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktsu-dev%2Fpersistenceprovider/lists"}