Clone
3
Home
Anatolii Hrynchuk edited this page 2026-05-06 01:25:58 +03:00

hrynco-ef

Reusable Entity Framework Core base library for HrynCo applications.

Solution

The solution (hrynco-ef.slnx) contains two projects:

Project Description
HrynCo.DAL.Abstract Infrastructure-agnostic contracts: entities, repository interfaces, unit of work, transactions, pagination. No EF Core dependency.
HrynCo.DAL.EF Entity Framework Core implementations of the abstract contracts. Depends on HrynCo.DAL.Abstract and EF Core.

The split allows consuming projects to reference only HrynCo.DAL.Abstract in domain/application layers, keeping those layers free of EF Core.

Packages

HrynCo.DAL.Abstract

Type Description
IEntity / IEntity<TId> Base entity contracts
Entity<TId> / Entity Base entity implementations with auto-generated Id
NamedEntity Entity with a Name property
IUnitOfWork Unit of work interface with transaction support
ITransaction Async transaction contract
PagedResult<T> Pagination result wrapper

HrynCo.DAL.EF

Type Description
BaseRepository<T> Base repository wrapping the EF repository (lazy)
BaseEfRepository<T> EF Core repository with full CRUD and DbContext access
IEfRepository<T> EF-specific repository interface
EfUnitOfWork EF Core unit of work implementation
EfTransactionAdapter Adapts EF transactions to ITransaction

Usage

Reference HrynCo.DAL.Abstract for contracts only (domain/application layers). Reference HrynCo.DAL.EF for the full EF Core implementation (infrastructure layer).

// 1. Define your entity
public class Product : Entity
{
    public string Name { get; set; } = string.Empty;
}

// 2. Implement your repository
public class ProductRepository : BaseEfRepository<YourDbContext, Product, Guid>
{
    public ProductRepository(YourDbContext context) : base(context) { }
}

// 3. Register in DI
services.AddScoped<IEfRepository<Product, Guid>, ProductRepository>();
services.AddScoped<IUnitOfWork, EfUnitOfWork<YourDbContext>>();

Pages

  • Versioning — how versions are bumped and packages published
  • Class Diagram — full class and interface hierarchy
  • IT-642 — Extract PagedResult builder as reusable IQueryable<T> extension