Indiko.Blocks.DataAccess.Abstractions 2.1.2

dotnet add package Indiko.Blocks.DataAccess.Abstractions --version 2.1.2
                    
NuGet\Install-Package Indiko.Blocks.DataAccess.Abstractions -Version 2.1.2
                    
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.2" />
                    
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.2" />
                    
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.2
                    
#r "nuget: Indiko.Blocks.DataAccess.Abstractions, 2.1.2"
                    
#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.2
                    
#: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.2
                    
Install as a Cake Addin
#tool nuget:?package=Indiko.Blocks.DataAccess.Abstractions&version=2.1.2
                    
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.2 281 12/18/2025
2.1.1 679 12/2/2025
2.1.0 664 12/2/2025
2.0.0 281 9/17/2025
1.7.23 353 9/8/2025
1.7.22 204 9/8/2025
1.7.21 218 8/14/2025
1.7.20 247 6/23/2025
1.7.19 223 6/3/2025
1.7.18 218 5/29/2025
1.7.17 235 5/26/2025
1.7.15 186 4/12/2025
1.7.14 194 4/11/2025
1.7.13 186 3/29/2025
1.7.12 197 3/28/2025
1.7.11 196 3/28/2025
1.7.10 224 3/28/2025
1.7.9 214 3/28/2025
1.7.8 194 3/28/2025
1.7.5 218 3/17/2025
1.7.4 201 3/16/2025
1.7.3 203 3/16/2025
1.7.2 192 3/16/2025
1.7.1 266 3/11/2025
1.6.8 231 3/11/2025
1.6.7 311 3/4/2025
1.6.6 197 2/26/2025
1.6.5 187 2/20/2025
1.6.4 157 2/20/2025
1.6.3 185 2/5/2025
1.6.2 184 1/24/2025
1.6.1 153 1/24/2025
1.6.0 144 1/16/2025
1.5.2 181 1/16/2025
1.5.1 214 11/3/2024
1.5.0 206 10/26/2024
1.3.2 174 10/24/2024
1.3.0 177 10/10/2024
1.2.5 174 10/9/2024
1.2.4 197 10/8/2024
1.2.1 173 10/3/2024
1.2.0 188 9/29/2024
1.1.1 187 9/23/2024
1.1.0 189 9/18/2024
1.0.33 209 9/15/2024
1.0.28 188 8/28/2024
1.0.27 195 8/24/2024
1.0.26 219 7/7/2024
1.0.25 223 7/6/2024
1.0.24 192 6/25/2024
1.0.23 232 6/1/2024
1.0.22 205 5/14/2024
1.0.21 175 5/14/2024
1.0.20 202 4/8/2024
1.0.19 180 4/3/2024
1.0.18 223 3/23/2024
1.0.17 246 3/19/2024
1.0.16 198 3/19/2024
1.0.15 210 3/11/2024
1.0.14 237 3/10/2024
1.0.13 194 3/6/2024
1.0.12 236 3/1/2024
1.0.11 217 3/1/2024
1.0.10 196 3/1/2024
1.0.9 204 3/1/2024
1.0.8 213 2/19/2024
1.0.7 188 2/17/2024
1.0.6 193 2/17/2024
1.0.5 198 2/17/2024
1.0.4 197 2/7/2024
1.0.3 209 2/6/2024
1.0.1 187 2/6/2024
1.0.0 254 1/9/2024
1.0.0-preview99 201 12/22/2023
1.0.0-preview98 166 12/21/2023
1.0.0-preview97 204 12/21/2023
1.0.0-preview96 182 12/20/2023
1.0.0-preview95 186 12/20/2023
1.0.0-preview94 166 12/18/2023
1.0.0-preview93 345 12/13/2023
1.0.0-preview92 158 12/13/2023
1.0.0-preview91 211 12/12/2023
1.0.0-preview90 160 12/11/2023
1.0.0-preview89 191 12/11/2023
1.0.0-preview88 271 12/6/2023
1.0.0-preview87 200 12/6/2023
1.0.0-preview86 200 12/6/2023
1.0.0-preview85 205 12/6/2023
1.0.0-preview84 185 12/5/2023
1.0.0-preview83 236 12/5/2023
1.0.0-preview82 191 12/5/2023
1.0.0-preview81 199 12/4/2023
1.0.0-preview80 175 12/1/2023
1.0.0-preview77 163 12/1/2023
1.0.0-preview76 203 12/1/2023
1.0.0-preview75 188 12/1/2023
1.0.0-preview74 216 11/26/2023
1.0.0-preview73 210 11/7/2023
1.0.0-preview72 202 11/6/2023
1.0.0-preview71 240 11/3/2023
1.0.0-preview70 201 11/2/2023
1.0.0-preview69 190 11/2/2023
1.0.0-preview68 207 11/2/2023
1.0.0-preview67 216 11/2/2023
1.0.0-preview66 161 11/2/2023
1.0.0-preview65 206 11/2/2023
1.0.0-preview64 210 11/2/2023
1.0.0-preview63 214 11/2/2023
1.0.0-preview62 179 11/1/2023
1.0.0-preview61 180 11/1/2023
1.0.0-preview60 189 11/1/2023
1.0.0-preview59 188 11/1/2023
1.0.0-preview58 195 10/31/2023
1.0.0-preview57 195 10/31/2023
1.0.0-preview56 196 10/31/2023
1.0.0-preview55 201 10/31/2023
1.0.0-preview54 195 10/31/2023
1.0.0-preview53 207 10/31/2023
1.0.0-preview52 222 10/31/2023
1.0.0-preview51 220 10/31/2023
1.0.0-preview50 199 10/31/2023
1.0.0-preview48 196 10/31/2023
1.0.0-preview46 186 10/31/2023
1.0.0-preview45 193 10/31/2023
1.0.0-preview44 223 10/31/2023
1.0.0-preview43 180 10/31/2023
1.0.0-preview42 188 10/30/2023
1.0.0-preview41 182 10/30/2023
1.0.0-preview40 188 10/27/2023
1.0.0-preview39 206 10/27/2023
1.0.0-preview38 199 10/27/2023
1.0.0-preview37 219 10/27/2023
1.0.0-preview36 182 10/27/2023
1.0.0-preview35 184 10/27/2023
1.0.0-preview34 211 10/27/2023
1.0.0-preview33 209 10/26/2023
1.0.0-preview32 194 10/26/2023
1.0.0-preview31 204 10/26/2023
1.0.0-preview30 207 10/26/2023
1.0.0-preview29 192 10/26/2023
1.0.0-preview28 214 10/26/2023
1.0.0-preview27 217 10/26/2023
1.0.0-preview26 221 10/25/2023
1.0.0-preview25 212 10/23/2023
1.0.0-preview24 210 10/23/2023
1.0.0-preview23 229 10/23/2023
1.0.0-preview22 191 10/23/2023
1.0.0-preview21 197 10/23/2023
1.0.0-preview20 220 10/20/2023
1.0.0-preview19 225 10/19/2023
1.0.0-preview18 200 10/18/2023
1.0.0-preview16 185 10/11/2023
1.0.0-preview14 207 10/10/2023
1.0.0-preview13 206 10/10/2023
1.0.0-preview12 203 10/9/2023
1.0.0-preview11 212 10/9/2023
1.0.0-preview101 190 1/5/2024