DKNet

Entity Framework Core Extensions

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.

Components

Core Abstractions & Patterns

Domain Events & Lifecycle Management

Data Access & Security

Database Utilities

Architecture Role in DDD & Onion Architecture

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            │
└─────────────────────────────────────────────────────────────────┘

Key Design Patterns Implemented

1. Repository Pattern

2. Domain Events

3. Unit of Work

4. Data Authorization

DDD Implementation Benefits

1. Aggregate Consistency

2. Domain Events

3. Ubiquitous Language

4. Bounded Context Support

Onion Architecture Benefits

1. Dependency Inversion

2. Testability

3. Technology Agnostic

4. Separation of Concerns

Integration Patterns

1. Domain Entity with Events

public class Order : Entity, IEventEntity
{
    // Domain properties and business logic
    
    public void CompleteOrder()
    {
        Status = OrderStatus.Completed;
        AddEvent(new OrderCompletedEvent(Id, CustomerId));
    }
}

2. Repository Pattern Implementation

public interface IOrderRepository : IRepository<Order>
{
    Task<Order?> GetByOrderNumberAsync(string orderNumber);
}

public class OrderRepository : GenericRepository<Order>, IOrderRepository
{
    // Implementation in infrastructure layer
}

3. Domain Event Handling

public class OrderCompletedEventHandler : IEventHandler<OrderCompletedEvent>
{
    public async Task Handle(OrderCompletedEvent evt)
    {
        // Handle cross-aggregate concerns
        // Send notifications, update read models, etc.
    }
}

Performance & Scalability Features

Security & Compliance