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