Indiko.Blocks.DataAccess.Abstractions 2.1.1

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

Indiko.Blocks.DataAccess.Abstractions

Core abstractions for data access layer implementation in the Indiko framework, providing interfaces and base classes for repositories, unit of work, and database context management.

Overview

This package defines the fundamental contracts for implementing data access layers across different ORM providers (Entity Framework, MongoDB, Marten, etc.). It provides a consistent API for CRUD operations, querying, and transaction management.

Features

  • Generic Repository Pattern: Comprehensive IRepository<TEntity, TIdType> interface
  • Unit of Work: Transaction management abstraction
  • Database Context: Base classes for DbContext implementations
  • Model Builder: Configuration system for entity mappings
  • Entity Configuration Registry: Centralized entity configuration management
  • Manager Pattern: Service locator for repositories
  • Soft Delete Support: Built-in soft delete functionality
  • Paging & Filtering: Query, paging, and filtering operations
  • Aggregation Functions: Sum, Count, Min, Max, Average, GroupBy, Distinct
  • Async/Await: Full async support throughout
  • Change Tracking: Entity state management and dirty tracking
  • Multiple ID Types: Support for Guid, int, long, string, etc.

Installation

dotnet add package Indiko.Blocks.DataAccess.Abstractions

Key Interfaces

IRepository<TEntity, TIdType>

Comprehensive repository interface with over 50 methods for data operations.

public interface IRepository<TEntity, TIdType> where TEntity : class, IEntity<TIdType>
{
    // CRUD Operations
    ValueTask<bool> AddAsync(TEntity entity, CancellationToken cancellationToken = default);
    ValueTask<bool> UpdateAsync(TEntity entity, CancellationToken cancellationToken = default);
    ValueTask<bool> DeleteAsync(TEntity entity, bool useSoftDelete = true, CancellationToken cancellationToken = default);
    
    // Read Operations
    ValueTask<TEntity> ReadByIdAsync(TIdType id, CancellationToken cancellationToken = default);
    ValueTask<IEnumerable<TEntity>> ReadAllAsync(bool asNotracking = true, CancellationToken cancellationToken = default);
    ValueTask<IEnumerable<TEntity>> ReadManyByQueryAsync(Expression<Func<TEntity, bool>> where, ...);
    ValueTask<PagedList<TEntity>> ReadManyByQueryPagedAsync(Expression<Func<TEntity, bool>> where, int page = 1, int pageSize = 25, ...);
    
    // Aggregations
    ValueTask<int> CountAsync(Expression<Func<TEntity, bool>> where, ...);
    ValueTask<decimal> SumAsync(Expression<Func<TEntity, decimal>> where, ...);
    ValueTask<TResult> MaxAsync<TResult>(Expression<Func<TEntity, TResult>> where, ...);
    ValueTask<TResult> MinAsync<TResult>(Expression<Func<TEntity, TResult>> where, ...);
    ValueTask<double> AverageAsync(Expression<Func<TEntity, bool>> where, Expression<Func<TEntity, double>> averageBy, ...);
    
    // Advanced Queries
    ValueTask<IEnumerable<TResult>> GroupByAsync<TKey, TResult>(...);
    ValueTask<IEnumerable<TProperty>> DistinctAsync<TProperty>(...);
    ValueTask<bool> ExistsAsync(Expression<Func<TEntity, bool>> where, ...);
    
    // Batch Operations
    ValueTask<bool> AddRangeAsync(IEnumerable<TEntity> entities, ...);
    ValueTask<bool> UpdateRangeAsync(IEnumerable<TEntity> entities, ...);
    ValueTask<bool> DeleteRangeAsync(IEnumerable<TEntity> entities, ...);
}

IUnitOfWork

Transaction management interface.

public interface IUnitOfWork : IDisposable
{
    Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
    Task BeginTransactionAsync(CancellationToken cancellationToken = default);
    Task CommitTransactionAsync(CancellationToken cancellationToken = default);
    Task RollbackTransactionAsync(CancellationToken cancellationToken = default);
}

IManager

Service locator for accessing repositories.

public interface IManager
{
    IRepository<TEntity, TIdType> GetRepository<TEntity, TIdType>() 
        where TEntity : class, IEntity<TIdType>;
}

IDataAccessBlock

Marker interface for data access blocks.

public interface IDataAccessBlock : IBlock
{
}

Usage Examples

Basic CRUD Operations

public class UserService
{
    private readonly IRepository<User, Guid> _userRepository;
    private readonly IUnitOfWork _unitOfWork;

    public UserService(IRepository<User, Guid> userRepository, IUnitOfWork unitOfWork)
    {
        _userRepository = userRepository;
        _unitOfWork = unitOfWork;
    }

    // Create
    public async Task<User> CreateUserAsync(User user)
    {
        await _userRepository.AddAsync(user);
        await _unitOfWork.SaveChangesAsync();
        return user;
    }

    // Read
    public async Task<User> GetUserAsync(Guid id)
    {
        return await _userRepository.ReadByIdAsync(id);
    }

    // Update
    public async Task UpdateUserAsync(User user)
    {
        await _userRepository.UpdateAsync(user);
        await _unitOfWork.SaveChangesAsync();
    }

    // Delete (soft delete)
    public async Task DeleteUserAsync(Guid id)
    {
        await _userRepository.DeleteAsync(id, useSoftDelete: true);
        await _unitOfWork.SaveChangesAsync();
    }
}

Querying and Filtering

// Simple query
var activeUsers = await _userRepository.ReadManyByQueryAsync(u => u.IsActive);

// Query with ordering
var recentUsers = await _userRepository.ReadManyByQueryAsync(
    where: u => u.IsActive,
    orderBy: u => u.CreatedAt,
    orderByAscending: false
);

// Paged query
var pagedUsers = await _userRepository.ReadManyByQueryPagedAsync(
    where: u => u.IsActive && u.Email.Contains("@example.com"),
    page: 1,
    pageSize: 20
);

// Query with includes (navigation properties)
var usersWithOrders = await _userRepository.ReadManyByQueryWithIncludesAsync(
    where: u => u.IsActive,
    asNotracking: true,
    includes: "Orders", "Orders.Items"
);

// Query with projection
var userNames = await _userRepository.ReadByQueryWithSelectorAsync(
    where: u => u.IsActive,
    selector: u => new { u.Id, u.Name, u.Email }
);

Aggregations

// Count
int activeCount = await _userRepository.CountAsync(u => u.IsActive);

// Sum
decimal totalRevenue = await _userRepository.SumAsync(
    where: u => u.IsActive,
    sumBy: u => u.TotalPurchases
);

// Average
double averageAge = await _userRepository.AverageAsync(
    where: u => u.IsActive,
    averageBy: u => u.Age
);

// Min/Max
var oldestUser = await _userRepository.MaxAsync(u => u.Age);
var youngestUser = await _userRepository.MinAsync(u => u.Age);

// Group By
var usersByCountry = await _userRepository.GroupByAsync(
    filter: u => u.IsActive,
    groupBy: u => u.Country,
    selector: g => new 
    { 
        Country = g.Key, 
        Count = g.Count(),
        TotalRevenue = g.Sum(u => u.TotalPurchases)
    }
);

// Distinct
var countries = await _userRepository.DistinctAsync(
    selector: u => u.Country,
    filter: u => u.IsActive
);

Batch Operations

// Add multiple entities
var newUsers = new List<User> { user1, user2, user3 };
await _userRepository.AddRangeAsync(newUsers);
await _unitOfWork.SaveChangesAsync();

// Update multiple entities
await _userRepository.UpdateRangeAsync(usersToUpdate);
await _unitOfWork.SaveChangesAsync();

// Delete multiple entities
await _userRepository.DeleteRangeAsync(usersToDelete);
await _unitOfWork.SaveChangesAsync();

Transactions

public async Task TransferFundsAsync(Guid fromUserId, Guid toUserId, decimal amount)
{
    await _unitOfWork.BeginTransactionAsync();
    
    try
    {
        var fromUser = await _userRepository.ReadByIdAsync(fromUserId);
        var toUser = await _userRepository.ReadByIdAsync(toUserId);
        
        fromUser.Balance -= amount;
        toUser.Balance += amount;
        
        await _userRepository.UpdateAsync(fromUser);
        await _userRepository.UpdateAsync(toUser);
        
        await _unitOfWork.SaveChangesAsync();
        await _unitOfWork.CommitTransactionAsync();
    }
    catch
    {
        await _unitOfWork.RollbackTransactionAsync();
        throw;
    }
}

Using Manager Pattern

public class OrderService
{
    private readonly IManager _manager;
    private readonly IUnitOfWork _unitOfWork;

    public OrderService(IManager manager, IUnitOfWork unitOfWork)
    {
        _manager = manager;
        _unitOfWork = unitOfWork;
    }

    public async Task CreateOrderAsync(Order order)
    {
        var orderRepo = _manager.GetRepository<Order, Guid>();
        var userRepo = _manager.GetRepository<User, Guid>();
        
        var user = await userRepo.ReadByIdAsync(order.UserId);
        if (user == null) throw new Exception("User not found");
        
        await orderRepo.AddAsync(order);
        await _unitOfWork.SaveChangesAsync();
    }
}

Base Classes

BaseRepository<TEntity, TIdType>

Abstract base class for repository implementations.

public abstract class BaseRepository<TEntity, TIdType> : IRepository<TEntity, TIdType>
    where TEntity : class, IEntity<TIdType>
{
    protected abstract IQueryable<TEntity> GetQueryable();
    // ... common implementation
}

BaseDbContext

Abstract base class for database context implementations.

public abstract class BaseDbContext
{
    public abstract Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
    // ... common implementation
}

Entity Configuration

IEntityConfiguration<TEntity>

Interface for entity configuration.

public interface IEntityConfiguration<TEntity> where TEntity : class
{
    void Configure(IEntityBuilder<TEntity> builder);
}

EntityConfigurationRegistry

Registry for managing entity configurations.

public class EntityConfigurationRegistry : IEntityConfigurationRegistry
{
    public void Register<TEntity>(IEntityConfiguration<TEntity> configuration) 
        where TEntity : class;
    
    public IEnumerable<IEntityConfiguration<TEntity>> GetConfigurations<TEntity>() 
        where TEntity : class;
}

Enumerations

DatabaseType

public enum DatabaseType
{
    SqlServer,
    PostgreSQL,
    MySQL,
    MongoDB,
    SQLite,
    Oracle,
    MariaDB
}

OrmApproach

public enum OrmApproach
{
    EntityFramework,
    Dapper,
    MongoDB,
    Marten,
    NHibernate
}

Options

DataAccessOptions

public class DataAccessOptions
{
    public string ConnectionString { get; set; }
    public DatabaseType DatabaseType { get; set; }
    public OrmApproach OrmApproach { get; set; }
    public bool EnableSensitiveDataLogging { get; set; }
    public int CommandTimeout { get; set; }
}

Target Framework

  • .NET 10

Dependencies

  • Indiko.Common.Abstractions
  • Indiko.Blocks.Common.Abstractions

License

See LICENSE file in the repository root.

  • Indiko.Blocks.DataAccess.EntityFramework - Entity Framework Core implementation
  • Indiko.Blocks.DataAccess.MongoDb - MongoDB implementation
  • Indiko.Blocks.DataAccess.Marten - Marten (PostgreSQL) implementation
  • Indiko.Blocks.Common.Management - Block management system
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Indiko.Blocks.DataAccess.Abstractions:

Package Downloads
Indiko.Blocks.DataAccess.MongoDb

Building Blocks DataAccess Mongo DB

Indiko.Blocks.DataAccess.EntityFramework

Building Blocks DataAccess EntityFramework

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.1 38 12/2/2025
2.1.0 37 12/2/2025
2.0.0 273 9/17/2025
1.7.23 348 9/8/2025
1.7.22 193 9/8/2025
1.7.21 204 8/14/2025
1.7.20 235 6/23/2025
1.7.19 213 6/3/2025
1.7.18 210 5/29/2025
1.7.17 227 5/26/2025
1.7.15 180 4/12/2025
1.7.14 185 4/11/2025
1.7.13 178 3/29/2025
1.7.12 185 3/28/2025
1.7.11 187 3/28/2025
1.7.10 221 3/28/2025
1.7.9 205 3/28/2025
1.7.8 188 3/28/2025
1.7.5 210 3/17/2025
1.7.4 194 3/16/2025
1.7.3 194 3/16/2025
1.7.2 189 3/16/2025
1.7.1 257 3/11/2025
1.6.8 227 3/11/2025
1.6.7 303 3/4/2025
1.6.6 186 2/26/2025
1.6.5 174 2/20/2025
1.6.4 150 2/20/2025
1.6.3 175 2/5/2025
1.6.2 176 1/24/2025
1.6.1 146 1/24/2025
1.6.0 136 1/16/2025
1.5.2 176 1/16/2025
1.5.1 204 11/3/2024
1.5.0 201 10/26/2024
1.3.2 168 10/24/2024
1.3.0 167 10/10/2024
1.2.5 169 10/9/2024
1.2.4 187 10/8/2024
1.2.1 169 10/3/2024
1.2.0 183 9/29/2024
1.1.1 183 9/23/2024
1.1.0 186 9/18/2024
1.0.33 199 9/15/2024
1.0.28 184 8/28/2024
1.0.27 189 8/24/2024
1.0.26 213 7/7/2024
1.0.25 222 7/6/2024
1.0.24 185 6/25/2024
1.0.23 227 6/1/2024
1.0.22 194 5/14/2024
1.0.21 173 5/14/2024
1.0.20 196 4/8/2024
1.0.19 175 4/3/2024
1.0.18 220 3/23/2024
1.0.17 239 3/19/2024
1.0.16 192 3/19/2024
1.0.15 201 3/11/2024
1.0.14 229 3/10/2024
1.0.13 189 3/6/2024
1.0.12 227 3/1/2024
1.0.11 210 3/1/2024
1.0.10 189 3/1/2024
1.0.9 196 3/1/2024
1.0.8 211 2/19/2024
1.0.7 183 2/17/2024
1.0.6 189 2/17/2024
1.0.5 191 2/17/2024
1.0.4 192 2/7/2024
1.0.3 203 2/6/2024
1.0.1 180 2/6/2024
1.0.0 244 1/9/2024
1.0.0-preview99 194 12/22/2023
1.0.0-preview98 160 12/21/2023
1.0.0-preview97 200 12/21/2023
1.0.0-preview96 179 12/20/2023
1.0.0-preview95 177 12/20/2023
1.0.0-preview94 162 12/18/2023
1.0.0-preview93 339 12/13/2023
1.0.0-preview92 153 12/13/2023
1.0.0-preview91 205 12/12/2023
1.0.0-preview90 157 12/11/2023
1.0.0-preview89 186 12/11/2023
1.0.0-preview88 265 12/6/2023
1.0.0-preview87 198 12/6/2023
1.0.0-preview86 194 12/6/2023
1.0.0-preview85 199 12/6/2023
1.0.0-preview84 181 12/5/2023
1.0.0-preview83 232 12/5/2023
1.0.0-preview82 186 12/5/2023
1.0.0-preview81 193 12/4/2023
1.0.0-preview80 172 12/1/2023
1.0.0-preview77 156 12/1/2023
1.0.0-preview76 196 12/1/2023
1.0.0-preview75 184 12/1/2023
1.0.0-preview74 210 11/26/2023
1.0.0-preview73 204 11/7/2023
1.0.0-preview72 195 11/6/2023
1.0.0-preview71 230 11/3/2023
1.0.0-preview70 196 11/2/2023
1.0.0-preview69 183 11/2/2023
1.0.0-preview68 202 11/2/2023
1.0.0-preview67 211 11/2/2023
1.0.0-preview66 159 11/2/2023
1.0.0-preview65 200 11/2/2023
1.0.0-preview64 207 11/2/2023
1.0.0-preview63 207 11/2/2023
1.0.0-preview62 178 11/1/2023
1.0.0-preview61 173 11/1/2023
1.0.0-preview60 183 11/1/2023
1.0.0-preview59 186 11/1/2023
1.0.0-preview58 187 10/31/2023
1.0.0-preview57 194 10/31/2023
1.0.0-preview56 194 10/31/2023
1.0.0-preview55 198 10/31/2023
1.0.0-preview54 189 10/31/2023
1.0.0-preview53 201 10/31/2023
1.0.0-preview52 213 10/31/2023
1.0.0-preview51 213 10/31/2023
1.0.0-preview50 193 10/31/2023
1.0.0-preview48 186 10/31/2023
1.0.0-preview46 180 10/31/2023
1.0.0-preview45 187 10/31/2023
1.0.0-preview44 213 10/31/2023
1.0.0-preview43 177 10/31/2023
1.0.0-preview42 182 10/30/2023
1.0.0-preview41 178 10/30/2023
1.0.0-preview40 182 10/27/2023
1.0.0-preview39 200 10/27/2023
1.0.0-preview38 194 10/27/2023
1.0.0-preview37 215 10/27/2023
1.0.0-preview36 180 10/27/2023
1.0.0-preview35 180 10/27/2023
1.0.0-preview34 203 10/27/2023
1.0.0-preview33 204 10/26/2023
1.0.0-preview32 190 10/26/2023
1.0.0-preview31 200 10/26/2023
1.0.0-preview30 199 10/26/2023
1.0.0-preview29 189 10/26/2023
1.0.0-preview28 206 10/26/2023
1.0.0-preview27 208 10/26/2023
1.0.0-preview26 217 10/25/2023
1.0.0-preview25 207 10/23/2023
1.0.0-preview24 206 10/23/2023
1.0.0-preview23 221 10/23/2023
1.0.0-preview22 183 10/23/2023
1.0.0-preview21 195 10/23/2023
1.0.0-preview20 215 10/20/2023
1.0.0-preview19 219 10/19/2023
1.0.0-preview18 195 10/18/2023
1.0.0-preview16 180 10/11/2023
1.0.0-preview14 203 10/10/2023
1.0.0-preview13 199 10/10/2023
1.0.0-preview12 199 10/9/2023
1.0.0-preview11 206 10/9/2023
1.0.0-preview101 182 1/5/2024