Akay.To.EF 1.0.8

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

Akay.To.EF

Infraestructura para aplicaciones que usan Entity Framework Core: DbContext base, interceptores, repositorio genérico, Unit of Work, multi-tenancy, soft delete, auditoría, outbox y helpers de consulta. Depende de Akay.To.Core.

¿Para qué sirve?

Para ahorrarte el "plumbing" de EF Core en cada proyecto: un DbContext que ya implementa IUnitOfWork, interceptores que rellenan auditoría y tenants automáticamente, soft delete por interfaz, repositorio genérico y extensiones de consulta listas para usar.

Funcionalidades

Leyenda

  • Implementa contrato de Core — el contrato está definido en Akay.To.Core y este paquete lo implementa.
  • Consume contratos de Core — las interfaces las implementa tu entidad; este paquete las usa.
  • Funcionalidad propia — implementada íntegramente en Akay.To.EF.

DbContext base

Hereda de BaseDbContext<TContext> (o TenantBaseDbContext<TContext, TTenantId> para multi-tenancy) y obtienes:

  • IUnitOfWork ya implementado (SaveChangesAsync)
  • CurrentUserId y CurrentTenantId desde el IUserContext
  • ApplyRuntimeSettings() — command timeout desde settings
  • Health check automático de conectividad

Soft delete mediante la interfaz ISoftDeletable

Implementa ISoftDeletable (y opcionalmente IUserSoftDeletable para DeletedBy) en la entidad y el SoftDeleteSaveChangesInterceptor convierte los Remove() en borrados lógicos: en vez de DELETE, escribe DeletedAt/DeletedBy. Todas las queries excluyen automáticamente los borrados gracias al global query filter.

Auditoría automática

Implementa IAuditable / IUserAuditable en la entidad y el AuditingSaveChangesInterceptor rellena CreatedAt/CreatedBy al insertar y UpdatedAt/UpdatedBy al modificar.

Multi-tenancy y ownership

Implementa IHasTenant / IHasOwner en la entidad y el TenantOwnershipSaveChangesInterceptor asigna TenantId y OwnerId automáticamente en entidades nuevas. Filtra con WhereTenant(), WhereOwner() y WhereTenantAndOwner().

Eventos de dominio y Outbox

El DomainEventsSaveChangesInterceptor centraliza el ciclo de vida de eventos durante SaveChanges:

  • Eventos IDomainEvent normales: se publican in-process antes/después del commit
  • Eventos IOutboxDomainEvent: se serializan a OutboxMessage en la misma transacción que los datos de negocio (consistencia transaccional con el bus)
  • OutboxEventWriter implementa IOutboxEventWriter (contrato de Core)

Auditoría de cambios (Change Tracking)

Implementa ITrackChanges en la entidad y el ChangeTrackingAuditSaveChangesInterceptor registra en la tabla __ChangeAudit cada Added/Modified/Deleted con OldValue/NewValue en JSON.

Repositorio genérico

Hereda de BaseRepository<TEntity, TId> y obtienes GetByIdAsync, ExistsAsync, Add, Update. Todos los métodos son virtual, así que puedes sobreescribirlos para añadir Include o consultas específicas.

Patrón Specification

Permite implementar fácilmente el patrón specification: define criterios reutilizables con Specification<TEntity> (AddCriteria, AddInclude, AddOrderBy), combínalos con And/Or y aplícalos con ApplySpecification() sobre cualquier IQueryable<T>.

var spec = new ExercisesByDifficulty(Difficulty.Advanced)
    .And(Specification<Exercise>.Create(e => e.Status == ExerciseStatus.Pending));

var result = await context.Set<Exercise>().ApplySpecification(spec).ToListAsync(ct);

Extensiones de consulta

  • ApplyOrdering(sort, asc, sortMap) — ordenación dinámica por diccionario
  • ApplyPaging / ToPagedResponseAsync — paginación sin COUNT extra (fetch pageSize + 1)
  • SqlHelpers.Contains(term) — LIKE seguro que escapa [, %, _

PersistenceResultExecutor

Envuelve SaveChangesAsync en Result: detecta constraints de BD (índice único, FK) por reflexión y los mapea a errores de negocio conocidos en vez de lanzar DbUpdateException.

Configuración de interceptores

Todos los interceptores se habilitan/deshabilitan desde DbContextInterceptorSettings en appsettings.json o por código.

Registro

services.AddTenantEFContext<AkayDbContext, int>(
    settings =>
    {
        settings.ConnectionString = connectionString;
        settings.Interceptors.Auditing = true;
        settings.Interceptors.SoftDelete = true;
        settings.Interceptors.DomainEvents = true;
        settings.Interceptors.ChangeTrackingAudit = true;
    },
    (sp, ob, s) => ob.UseSqlServer(s.ConnectionString, sql =>
        sql.ApplyDbContextSettings(s).EnableRetryOnFailure(3)));

AddTenantEFContext registra automáticamente: IUnitOfWork, IPersistenceResultExecutor, ICurrentTenant, los interceptores habilitados y el health check del DbContext.

Documentación

Consulta docs/ para guías detalladas (BaseDbContext, Interceptors, BaseRepository, QueryableExtensions, Specifications, PersistenceResultExecutor, Configuracion).

Changelog

1.0.8

  • 2026-09-10
  • Referencia de proyecto y mejora de documentación (a1b16aa)

1.0.7

  • 2026-09-05
  • Añade Remove/RemoveRange al repositorio y mejora docs (185d61e)

1.0.6

  • 2026-07-28
  • chore: bump Akay.To.Core to 1.1.5 (1f3d65d)

1.0.5

  • 2026-07-28
  • feat: add outbox event writer (8aee3ea)

1.0.4

  • 2026-07-21
  • refactor: reorganize packages by capability (2d71c5a)

1.0.3

  • 2026-07-16
  • Change tracking audit (54372fa)
  • feature/domainevents-outbox-trackchanges (7baacf8)

1.0.2

  • 2026-07-14
  • Domain events and Outbox (34b4d41)

1.0.1

  • 2026-07-10
  • chore: actualizado 1.0.1 (5c9fbf3)

0.0.4

  • 2026-07-06
  • chore: update nuget akay.to.core reference (87dbc84)
  • feat: Add Specification Pattern (9c40708)

0.0.3

0.0.2

  • 2026-07-02
  • Fix README.md (689ef04)
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 Akay.To.EF:

Package Downloads
Akay.To.EF.SqlServer

SQL Server provider helpers for Akay.To.EF

Akay.To.EF.Npgsql

PostgreSQL provider helpers for Akay.To.EF

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.8 100 9/10/2026
1.0.7 90 9/5/2026
1.0.6 127 7/28/2026
1.0.5 105 7/28/2026
1.0.4 123 7/21/2026
1.0.3 125 7/16/2026
1.0.2 118 7/14/2026
1.0.1 146 7/10/2026
0.0.4 119 7/6/2026
0.0.3 143 7/2/2026