SingularFrameworkCore.Repository.FileSystem.TextFile
0.2.0-beta
dotnet add package SingularFrameworkCore.Repository.FileSystem.TextFile --version 0.2.0-beta
NuGet\Install-Package SingularFrameworkCore.Repository.FileSystem.TextFile -Version 0.2.0-beta
<PackageReference Include="SingularFrameworkCore.Repository.FileSystem.TextFile" Version="0.2.0-beta" />
paket add SingularFrameworkCore.Repository.FileSystem.TextFile --version 0.2.0-beta
#r "nuget: SingularFrameworkCore.Repository.FileSystem.TextFile, 0.2.0-beta"
// Install SingularFrameworkCore.Repository.FileSystem.TextFile as a Cake Addin #addin nuget:?package=SingularFrameworkCore.Repository.FileSystem.TextFile&version=0.2.0-beta&prerelease // Install SingularFrameworkCore.Repository.FileSystem.TextFile as a Cake Tool #tool nuget:?package=SingularFrameworkCore.Repository.FileSystem.TextFile&version=0.2.0-beta&prerelease
SingularFrameworkCore.Repository.FileSystem.TextFile
A C# library that provides text file storage implementation for the SingularFrameworkCore repository interface. This library offers both synchronous and asynchronous implementations for storing string data in text files.
Features
- Text File Storage: Simple implementation for storing string data in text files
- Dual Implementation: Both synchronous (
TextFileRepository
) and asynchronous (TextFileRepositoryAsync
) versions - CRUD Operations: Full support for Create, Read, Update, and Delete operations
- Path Management: Secure file path handling
- Exception Handling: Custom exceptions for common scenarios
Installation
The package is available on NuGet. To install it, use the following command:
Install-Package SingularFrameworkCore.Repository.FileSystem.TextFile
Or using the .NET CLI:
dotnet add package SingularFrameworkCore.Repository.FileSystem.TextFile
Usage
Synchronous Implementation
using SingularFrameworkCore.Repository.FileSystem.TextFile;
// Create an instance with a file path
var repository = new TextFileRepository("path/to/your/file.txt");
// Create
repository.Create("Hello, World!");
// Read
string content = repository.Read();
// Update
repository.Update("Updated content");
// Delete
repository.Delete();
Asynchronous Implementation
using SingularFrameworkCore.Repository.FileSystem.TextFile;
// Create an instance with a file path
var repository = new TextFileRepositoryAsync("path/to/your/file.txt");
// Create
await repository.Create("Hello, World!");
// Read
string content = await repository.Read();
// Update
await repository.Update("Updated content");
// Delete
await repository.Delete();
Integration with SingularFrameworkCore
This library implements the ISingularCrudRepository<string>
and ISingularCrudAsyncRepository<string>
interfaces from SingularFrameworkCore, making it perfect for use with the Singular pipeline:
var singular = new Singular<MyClass, string>(
new TextFileRepository("data.txt"), // or TextFileRepositoryAsync
serializer,
preProcessors,
postProcessors
);
Exception Handling
The library includes a custom exception:
TextFileRepositoryFileAlreadyExistsException
: Thrown when attempting to create a file that already exists
try
{
repository.Create("content");
}
catch (TextFileRepositoryFileAlreadyExistsException ex)
{
// Handle the case where the file already exists
}
Requirements
- .NET Standard 8.0+
- SingularFrameworkCore
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Author
Made by Mohammad Ayaad 
Original Project
- SingularFrameworkCore - The core framework this implementation is built for
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- SingularFrameworkCore (>= 0.1.0-alpha)
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 |
---|---|---|
0.2.0-beta | 40 | 2/16/2025 |
0.1.0-alpha | 36 | 1/30/2025 |