Common.Repository
Repository and unit-of-work patterns for EF Core, as a NuGet package.
Details
- Role
- Author
- Started
- November 2022
- Language
- C#
- Platform
- Cross-platform
- Licence
- MIT
Overview
Nearly every EF Core codebase grows its own repository abstraction, and nearly every one re-solves the same problems slightly differently: where transactions begin, when SaveChanges is called, how paging and sorting are expressed.
Common.Repository is that layer extracted and published, so it is written once. It provides generic IRepository<T> and IQueryRepository<T> interfaces with EF Core implementations, separating read paths from write paths so queries can be optimised as read-only.
Unit of work handles transaction scope, with configurable save strategies — commit per operation or per unit of work, depending on whether the calling code wants granularity or atomicity. Paging and sorting are first-class through PagedList<T> and SortingDetails<T> rather than being reinvented per project.
This is the oldest project here, started in 2022, and it is on NuGet as BerrishDev.Common.Repository.
Highlights
- Generic IRepository<T> and IQueryRepository<T> with EF Core implementations
- Read/write separation so query paths can be optimised independently
- Unit of work with configurable PerOperation or PerUnitOfWork save strategies
- First-class pagination via PagedList<T> and PagingDetails
- Flexible sorting through SortingDetails<T> and SortItem
- Fully async, integrates with the .NET DI container; EF Core 6.0+
Built with
- .NET
- C#
- EF Core
- SQL Server