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