SingleScope.Persistence
4.0.0
dotnet add package SingleScope.Persistence --version 4.0.0
NuGet\Install-Package SingleScope.Persistence -Version 4.0.0
<PackageReference Include="SingleScope.Persistence" Version="4.0.0" />
<PackageVersion Include="SingleScope.Persistence" Version="4.0.0" />
<PackageReference Include="SingleScope.Persistence" />
paket add SingleScope.Persistence --version 4.0.0
#r "nuget: SingleScope.Persistence, 4.0.0"
#:package SingleScope.Persistence@4.0.0
#addin nuget:?package=SingleScope.Persistence&version=4.0.0
#tool nuget:?package=SingleScope.Persistence&version=4.0.0
SingleScope.Persistence
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. IUnitOfWorkInterface: 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:
- Check the GitHub Issues to see if your issue or idea has already been reported.
- If not, open a new issue to describe the bug or feature request.
- 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
mainbranch of the original repository.
- 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
Project link: https://github.com/muhirwanto-dev/singlescope-plugins/tree/main/source/SingleScope.Persistence
| 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 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. |
-
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.