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 287 12/18/2025
2.1.1 683 12/2/2025
2.1.0 668 12/2/2025
2.0.0 285 9/17/2025
1.7.23 358 9/8/2025
1.7.22 206 9/8/2025
1.7.21 219 8/14/2025
1.7.20 250 6/23/2025
1.7.19 226 6/3/2025
1.7.18 219 5/29/2025
1.7.17 236 5/26/2025
1.7.15 192 4/12/2025
1.7.14 196 4/11/2025
1.7.13 189 3/29/2025
1.7.12 202 3/28/2025
1.7.11 202 3/28/2025
1.7.10 225 3/28/2025
1.7.9 215 3/28/2025
1.7.8 196 3/28/2025
1.7.5 219 3/17/2025
1.7.4 205 3/16/2025
1.7.3 205 3/16/2025
1.7.2 195 3/16/2025
1.7.1 270 3/11/2025
1.6.8 234 3/11/2025
1.6.7 311 3/4/2025
1.6.6 201 2/26/2025
1.6.5 190 2/20/2025
1.6.4 161 2/20/2025
1.6.3 188 2/5/2025
1.6.2 188 1/24/2025
1.6.1 156 1/24/2025
1.6.0 146 1/16/2025
1.5.2 183 1/16/2025
1.5.1 215 11/3/2024
1.5.0 208 10/26/2024
1.3.2 178 10/24/2024
1.3.0 179 10/10/2024
1.2.5 178 10/9/2024
1.2.4 199 10/8/2024
1.2.1 174 10/3/2024
1.2.0 189 9/29/2024
1.1.1 190 9/23/2024
1.1.0 191 9/18/2024
1.0.33 213 9/15/2024
1.0.28 190 8/28/2024
1.0.27 198 8/24/2024
1.0.26 220 7/7/2024
1.0.25 228 7/6/2024
1.0.24 194 6/25/2024
1.0.23 232 6/1/2024
1.0.22 208 5/14/2024
1.0.21 178 5/14/2024
1.0.20 206 4/8/2024
1.0.19 186 4/3/2024
1.0.18 225 3/23/2024
1.0.17 248 3/19/2024
1.0.16 201 3/19/2024
1.0.15 212 3/11/2024
1.0.14 239 3/10/2024
1.0.13 195 3/6/2024
1.0.12 238 3/1/2024
1.0.11 220 3/1/2024
1.0.10 199 3/1/2024
1.0.9 207 3/1/2024
1.0.8 215 2/19/2024
1.0.7 190 2/17/2024
1.0.6 197 2/17/2024
1.0.5 200 2/17/2024
1.0.4 200 2/7/2024
1.0.3 210 2/6/2024
1.0.1 190 2/6/2024
1.0.0 258 1/9/2024
1.0.0-preview99 205 12/22/2023
1.0.0-preview98 169 12/21/2023
1.0.0-preview97 205 12/21/2023
1.0.0-preview96 183 12/20/2023
1.0.0-preview95 187 12/20/2023
1.0.0-preview94 168 12/18/2023
1.0.0-preview93 347 12/13/2023
1.0.0-preview92 160 12/13/2023
1.0.0-preview91 214 12/12/2023
1.0.0-preview90 162 12/11/2023
1.0.0-preview89 191 12/11/2023
1.0.0-preview88 276 12/6/2023
1.0.0-preview87 204 12/6/2023
1.0.0-preview86 204 12/6/2023
1.0.0-preview85 206 12/6/2023
1.0.0-preview84 186 12/5/2023
1.0.0-preview83 241 12/5/2023
1.0.0-preview82 193 12/5/2023
1.0.0-preview81 202 12/4/2023
1.0.0-preview80 178 12/1/2023
1.0.0-preview77 167 12/1/2023
1.0.0-preview76 208 12/1/2023
1.0.0-preview75 191 12/1/2023
1.0.0-preview74 217 11/26/2023
1.0.0-preview73 211 11/7/2023
1.0.0-preview72 205 11/6/2023
1.0.0-preview71 243 11/3/2023
1.0.0-preview70 203 11/2/2023
1.0.0-preview69 191 11/2/2023
1.0.0-preview68 207 11/2/2023
1.0.0-preview67 218 11/2/2023
1.0.0-preview66 162 11/2/2023
1.0.0-preview65 207 11/2/2023
1.0.0-preview64 212 11/2/2023
1.0.0-preview63 215 11/2/2023
1.0.0-preview62 181 11/1/2023
1.0.0-preview61 182 11/1/2023
1.0.0-preview60 195 11/1/2023
1.0.0-preview59 191 11/1/2023
1.0.0-preview58 197 10/31/2023
1.0.0-preview57 200 10/31/2023
1.0.0-preview56 199 10/31/2023
1.0.0-preview55 203 10/31/2023
1.0.0-preview54 197 10/31/2023
1.0.0-preview53 208 10/31/2023
1.0.0-preview52 223 10/31/2023
1.0.0-preview51 221 10/31/2023
1.0.0-preview50 202 10/31/2023
1.0.0-preview48 197 10/31/2023
1.0.0-preview46 189 10/31/2023
1.0.0-preview45 195 10/31/2023
1.0.0-preview44 224 10/31/2023
1.0.0-preview43 183 10/31/2023
1.0.0-preview42 190 10/30/2023
1.0.0-preview41 184 10/30/2023
1.0.0-preview40 191 10/27/2023
1.0.0-preview39 207 10/27/2023
1.0.0-preview38 200 10/27/2023
1.0.0-preview37 221 10/27/2023
1.0.0-preview36 185 10/27/2023
1.0.0-preview35 190 10/27/2023
1.0.0-preview34 214 10/27/2023
1.0.0-preview33 212 10/26/2023
1.0.0-preview32 196 10/26/2023
1.0.0-preview31 207 10/26/2023
1.0.0-preview30 209 10/26/2023
1.0.0-preview29 194 10/26/2023
1.0.0-preview28 216 10/26/2023
1.0.0-preview27 219 10/26/2023
1.0.0-preview26 223 10/25/2023
1.0.0-preview25 214 10/23/2023
1.0.0-preview24 212 10/23/2023
1.0.0-preview23 231 10/23/2023
1.0.0-preview22 193 10/23/2023
1.0.0-preview21 199 10/23/2023
1.0.0-preview20 222 10/20/2023
1.0.0-preview19 226 10/19/2023
1.0.0-preview18 204 10/18/2023
1.0.0-preview16 188 10/11/2023
1.0.0-preview14 210 10/10/2023
1.0.0-preview13 208 10/10/2023
1.0.0-preview12 205 10/9/2023
1.0.0-preview11 217 10/9/2023
1.0.0-preview101 194 1/5/2024