NPv.DataAccess.Abstractions
2.6.0
dotnet add package NPv.DataAccess.Abstractions --version 2.6.0
NuGet\Install-Package NPv.DataAccess.Abstractions -Version 2.6.0
<PackageReference Include="NPv.DataAccess.Abstractions" Version="2.6.0" />
<PackageVersion Include="NPv.DataAccess.Abstractions" Version="2.6.0" />
<PackageReference Include="NPv.DataAccess.Abstractions" />
paket add NPv.DataAccess.Abstractions --version 2.6.0
#r "nuget: NPv.DataAccess.Abstractions, 2.6.0"
#:package NPv.DataAccess.Abstractions@2.6.0
#addin nuget:?package=NPv.DataAccess.Abstractions&version=2.6.0
#tool nuget:?package=NPv.DataAccess.Abstractions&version=2.6.0
NPv.DataAccess.Abstractions
Minimal interface contract for generic repository access in .NET applications.
π’ Version status
- v2.6 is the new stable version of
NPv.DataAccess.Abstractionsand is recommended for all new and existing integrations. - Previous versions are now considered out of service and are no longer maintained.
β¨ Overview
This library defines core abstractions for working with persistent data in a clean, provider-agnostic way. It includes:
IGenericRepositoryβ for standard CRUD operations on aggregate roots or entitiesISqlExecutorβ for executing raw SQL queries and commands asynchronously
These abstractions are designed to support layered architectures, promote separation of concerns, and enable swapping implementations (e.g., EF Core, Dapper) with minimal friction.
π§± Interfaces
IGenericRepository
Standard CRUD contract for entity-oriented persistence:
Task<TEntity?> GetAsync<TEntity>(Guid id, CancellationToken ct, IReadOnlyCollection<string>? includes = null);
Task<TEntity?> GetAsync<TEntity>(Expression<Func<TEntity, bool>>? filter, CancellationToken ct, IReadOnlyCollection<string>? includes = null);
Task<IEnumerable<TEntity>> ListAsync<TEntity>(
CancellationToken ct,
Expression<Func<TEntity, bool>>? filter = null,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>>? orderBy = null,
IReadOnlyCollection<string>? includes = null);
Task<IEnumerable<TEntity>> PageAsync<TEntity>(
int page,
int pageSize,
CancellationToken ct,
Expression<Func<TEntity, bool>>? filter = null,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>>? orderBy = null,
IReadOnlyCollection<string>? includes = null);
Task<int> CountAsync<TEntity>(CancellationToken ct, Expression<Func<TEntity, bool>>? filter = null);
Task AddAsync<TEntity>(TEntity entity, CancellationToken ct);
Task DeleteAsync<TEntity>(Guid id, CancellationToken ct);
Include examples (current behavior)
includes uses string-based navigation paths:
var order = await repo.GetAsync<Order>(
id,
ct,
new[] { "Items", "Customer", "Customer.Address" });
var orders = await repo.ListAsync<Order>(
ct,
filter: x => x.Status == OrderStatus.Created,
includes: new[] { "Items.Product" });
ISqlExecutor
Lightweight abstraction over raw SQL execution, ideal for high-performance scenarios using Dapper or similar tools:
Task<T> QueryFirstAsync<T>(string sql, CancellationToken ct, object? parameters = null);
Task<T?> QueryFirstOrDefaultAsync<T>(string sql, CancellationToken ct, object? parameters = null);
Task<T> QuerySingleAsync<T>(string sql, CancellationToken ct, object? parameters = null);
Task<T?> QuerySingleOrDefaultAsync<T>(string sql, CancellationToken ct, object? parameters = null);
Task<IEnumerable<T>> QueryAsync<T>(string sql, CancellationToken ct, object? parameters = null);
Task<int> ExecuteAsync(string sql, CancellationToken ct, object? parameters = null);
βΉοΈ CancellationToken
All async methods require a CancellationToken ct.
Pass the application/request token from top-level boundaries so cancellation flows into repository/SQL layers.
If no token is available, pass CancellationToken.None explicitly at the call site.
Cancellation is propagated into EF Core/Dapper operations; OperationCanceledException is allowed to bubble.
public sealed class OrdersController(IGenericRepository repo)
{
[HttpPost]
public async Task<IActionResult> Create(CreateOrderRequest request, CancellationToken ct)
{
await repo.AddAsync(new Order { /* ... */ }, ct);
return Ok();
}
}
π§ Usage
Implement the interface in your data layer (e.g., using EF Core):
For IGenericRepository
public class EfGenericRepository : IGenericRepository { ... }
For ISqlExecutor
Implement using your SQL technology of choice, e.g. via Dapper:
public class DapperSqlExecutor : ISqlExecutor { ... }
Inject ISqlExecutor where you need to run raw SQL without managing connections or boilerplate manually.
π¦ Installation
This package is published as part of the NPv.Foundation.Net architecture.
To install via NuGet:
dotnet add package NPv.DataAccess.Abstractions
π§© Related packages
NPv.DataAccess.Efβ EF Core implementation ofIGenericRepositoryNPv.DataAccess.Dapper.Executorβ Dapper-based implementation ofISqlExecutor
Author's Note
This library grew out of my long-standing personal interest in structuring and publishing open source packages. Over time, Iβve revisited and refined earlier internal utilities and ideas, giving them a more consistent shape and preparing them for wider reuse. Along the way, Iβve also taken the opportunity to explore how open source distribution and licensing work in the .NET ecosystem.
Itβs a small step toward something Iβve always wanted to try β sharing practical, minimal tools that reflect years of learning, experimentation, and refinement.
Hopefully, someone finds it useful.
Nikolai π
βοΈ License
MIT β you are free to use this in commercial and open-source software.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- NPv.Domain.Core (>= 2.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on NPv.DataAccess.Abstractions:
| Package | Downloads |
|---|---|
|
NPv.DataAccess.Ef
NPv's IGenericRepository realisation for EF including: IDbContextFactory, IDbContextProvider, PerRequestDbContextProvider, ConsoleDbContextProvider |
|
|
NPv.DataAccess.Dapper.Executor
Dapper-based implementation of ISqlExecutor for raw SQL access in .NET applications. Wraps common Dapper methods and manages connection lifecycle. |
GitHub repositories
This package is not used by any popular GitHub repositories.