SingleScope.Persistence 4.0.0

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

SingleScope.Persistence

NuGet Version NuGet Downloads License GitHub Issues GitHub Stars GitHub Forks Contributions Welcome

Overview

SingleScope.Persistence is a C# .NET library providing core abstractions and building blocks for the data persistence layer of your applications. It aims to promote cleaner architecture, testability, and flexibility by offering common interfaces and patterns for interacting with data sources. While it facilitates the implementation of patterns like Repository and Unit of Work, its scope extends to general persistence concerns, providing a solid base for your data access strategy.

Key Features

  • Core Abstractions for Data Persistence: Provides fundamental interfaces and potentially base classes relevant to various data persistence tasks.
  • Facilitates Data Access Patterns: Simplifies the implementation of common patterns like Repository and Unit of Work.
  • Generic IReadWriteRepository<TEntity>: Defines standard data access operations (Add, Update, Delete, GetAll, Find, etc.) adaptable for any entity.
  • IUnitOfWork Interface: Offers a mechanism for managing atomic operations and coordinating changes across multiple data operations within a single transaction.
  • Promotes Separation of Concerns: Helps isolate data access logic from your domain and application layers.
  • Dependency Injection Friendly: Designed for seamless integration with standard .NET dependency injection containers.

Installation

This library primarily provides abstractions. You will typically need to implement the provided interfaces based on your chosen data access technology (e.g., Entity Framework Core, Dapper, NHibernate, etc.), or potentially use a separate companion implementation package if available.

Install the abstractions package via NuGet:

Package Manager Console:

Install-Package SingleScope.Persistence

.NET CLI

dotnet add package SingleScope.Persistence

Usage

This library provides several abstractions for persistence. Below is an example demonstrating how to use the IReadWriteRepository<TEntity> and IUnitOfWork interfaces, which are common components facilitated by this library. You might find other useful interfaces or base classes within the library depending on your specific persistence needs.

Define Your Entity

Implement your entity with IEntity<TKey> interface.

public class Product : IEntity<int>
{
    public int Id { get; set; }
    public string Name { get; set; }
    public decimal Price { get; set; }
}

Implement IReadWriteRepository<TEntity> and IUnitOfWork

// Read-Write repository
public class YourRwRepository<TEntity> : IReadWriteRepository<TEntity>
    where TEntity : class, IEntity
{   
}

// Read-Only repository
public class YourRoRepository<TEntity> : IReadRepository<TEntity>
    where TEntity : class, IEntity
{
}

// Unit of work
public class YourUnitOfWork<TContext> : IUnitOfWork<TContext>
    where TContext : DbContext
{
}

public class YourUnitOfWork : IUnitOfWork
{
}

SingleScope.Persistence.EFCore already have the implementation of both IReadWriteRepository and IUnitOfWork specific to EntityFrameworkCore.

Configure Dependency Injection

// Inject the services in Program.cs

services.AddScoped<IReadWriteRepository<Entity>, YourRwRepository<Entity>>();
services.AddScoped<IReadRepository<Entity>, YourRoRepository<Entity>>();
services.AddScoped<IUnitOfWork<DbContext>, YourUnitOfWork<DbContext>>();

Contributions

Contributions are welcome! If you encounter a bug, have a suggestion, or want to contribute code, please follow these steps:

  1. Check the GitHub Issues to see if your issue or idea has already been reported.
  2. If not, open a new issue to describe the bug or feature request.
  3. For code contributions:
    • Fork the Project repository.
    • Create your Feature Branch (git checkout -b feature/YourAmazingFeature).
    • Commit your Changes (git commit -m 'Add YourAmazingFeature'). Adhere to conventional commit messages if possible.
    • Push to the Branch (git push origin feature/YourAmazingFeature).
    • Open a Pull Request against the main branch of the original repository.
  4. Please try to follow the existing coding style and include unit tests for new or modified functionality.

License

Distributed under the MIT License. See the LICENSE file in the repository for more information.

Contact

@muhirwanto-dev

Project link: https://github.com/muhirwanto-dev/singlescope-plugins/tree/main/source/SingleScope.Persistence

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on SingleScope.Persistence:

Package Downloads
SingleScope.Persistence.EFCore

`SingleScope.Persistence.EFCore` implements Repository and Unit of Work abstraction using `EntityFrameworkCore`.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.0 182 7/7/2025
3.2.0 255 4/18/2025
3.1.2 244 4/16/2025
2.3.0 189 3/19/2025
2.2.0 252 3/8/2025
2.1.1 370 3/5/2025 2.1.1 is deprecated because it has critical bugs.
2.1.0 141 2/27/2025