The EfCore Extensions provide comprehensive enhancements to Entity Framework Core that implement repository patterns, domain events, data access abstractions, and advanced EF Core functionality specifically designed for Domain-Driven Design (DDD) and Onion Architecture patterns.
The EfCore Extensions form the Infrastructure Layer in the Onion Architecture, providing all data access concerns while maintaining proper dependency inversion:
┌─────────────────────────────────────────────────────────────────┐
│ 🌐 Presentation Layer │
│ (Controllers, API Endpoints) │
└─────────────────────────┬───────────────────────────────────────┘
│
┌─────────────────────────┴───────────────────────────────────────┐
│ 🎯 Application Layer │
│ (Use Cases, Application Services) │
│ │
│ Dependencies: Repository Interfaces (from Domain) │
└─────────────────────────┬───────────────────────────────────────┘
│
┌─────────────────────────┴───────────────────────────────────────┐
│ 💼 Domain Layer │
│ (Entities, Aggregates, Domain Services) │
│ │
│ • IEventEntity (from EfCore.Abstractions) │
│ • Domain Events (published via EfCore.Events) │
│ • Repository Interfaces (from EfCore.Repos.Abstractions) │
└─────────────────────────┬───────────────────────────────────────┘
│
┌─────────────────────────┴───────────────────────────────────────┐
│ 🗄️ Infrastructure Layer │
│ (Data Access, Persistence) │
│ │
│ 🗃️ DKNet.EfCore.Repos - Repository Implementations │
│ 📋 DKNet.EfCore.Events - Domain Event Dispatching │
│ 🔒 DKNet.EfCore.DataAuthorization - Access Control │
│ ⚡ DKNet.EfCore.Hooks - Lifecycle Management │
│ ⚙️ DKNet.EfCore.Extensions - EF Core Enhancements │
│ 🔧 DKNet.EfCore.Relational.Helpers - DB Utilities │
└─────────────────────────────────────────────────────────────────┘
public class Order : Entity, IEventEntity
{
// Domain properties and business logic
public void CompleteOrder()
{
Status = OrderStatus.Completed;
AddEvent(new OrderCompletedEvent(Id, CustomerId));
}
}
public interface IOrderRepository : IRepository<Order>
{
Task<Order?> GetByOrderNumberAsync(string orderNumber);
}
public class OrderRepository : GenericRepository<Order>, IOrderRepository
{
// Implementation in infrastructure layer
}
public class OrderCompletedEventHandler : IEventHandler<OrderCompletedEvent>
{
public async Task Handle(OrderCompletedEvent evt)
{
// Handle cross-aggregate concerns
// Send notifications, update read models, etc.
}
}