SingularFrameworkCore.Repository.FileSystem.TextFile 0.2.0-beta

This is a prerelease version of SingularFrameworkCore.Repository.FileSystem.TextFile.
dotnet add package SingularFrameworkCore.Repository.FileSystem.TextFile --version 0.2.0-beta
                    
NuGet\Install-Package SingularFrameworkCore.Repository.FileSystem.TextFile -Version 0.2.0-beta
                    
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="SingularFrameworkCore.Repository.FileSystem.TextFile" Version="0.2.0-beta" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SingularFrameworkCore.Repository.FileSystem.TextFile" Version="0.2.0-beta" />
                    
Directory.Packages.props
<PackageReference Include="SingularFrameworkCore.Repository.FileSystem.TextFile" />
                    
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 SingularFrameworkCore.Repository.FileSystem.TextFile --version 0.2.0-beta
                    
#r "nuget: SingularFrameworkCore.Repository.FileSystem.TextFile, 0.2.0-beta"
                    
#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.
#addin nuget:?package=SingularFrameworkCore.Repository.FileSystem.TextFile&version=0.2.0-beta&prerelease
                    
Install SingularFrameworkCore.Repository.FileSystem.TextFile as a Cake Addin
#tool nuget:?package=SingularFrameworkCore.Repository.FileSystem.TextFile&version=0.2.0-beta&prerelease
                    
Install SingularFrameworkCore.Repository.FileSystem.TextFile as a Cake Tool

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 MohammadAyaad

Original Project

Product 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. 
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
0.2.0-beta 66 2/16/2025
0.1.0-alpha 53 1/30/2025