Lewee.Infrastructure.Data 0.40.3

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

Lewee.Infrastructure.Data

Entity Framework Core integration for domain-driven design applications with repository pattern, domain event dispatching, and audit tracking.

Purpose

This package provides the data access layer infrastructure for applications using Lewee dependencies. It includes Entity Framework Core configuration helpers, repository implementation, domain event dispatching via the outbox pattern, and automatic audit field population.

Dependencies

  • Lewee.Domain - Domain layer abstractions
  • MediatR - For domain event notification dispatching
  • Microsoft.EntityFrameworkCore - ORM framework
  • Microsoft.EntityFrameworkCore.Relational - Relational database support
  • Microsoft.Extensions.Configuration.Binder - Configuration binding
  • Microsoft.Extensions.DependencyModel - Assembly scanning
  • Microsoft.Extensions.Hosting.Abstractions - Hosting abstractions

Components

Entity Configuration Classes

Abstract base classes for configuring Entity Framework entity mappings:

Class Purpose
AuditableRecordConfiguration<T> Base configuration for entities extending AuditableRecord
EntityConfiguration<T> Configuration for entities with soft-delete support
AggregateRootConfiguration<T> Configuration for aggregate roots with domain events
RelationshipConfiguration<T> Configuration for many-to-many relationship entities
EnumEntityConfiguration<TEnum> Configuration for enum lookup tables
DomainEventReferenceConfiguration Configuration for domain event outbox table
QueryProjectionReferenceConfiguration Configuration for query projection tracking

Database Context

ApplicationDbContext<TContext>

Abstract base class for application database contexts with domain event and query projection support:

public class MyDbContext : ApplicationDbContext<MyDbContext>
{
    public MyDbContext(DbContextOptions<MyDbContext> options)
        : base(options)
    {
    }

    public DbSet<Order> Orders { get; set; }
}

Interceptors

Interceptor Purpose
AuditDetailsSaveChangesInterceptor Populates CreatedBy, CreatedAtUtc, ModifiedBy, ModifiedAtUtc fields
DomainEventSaveChangesInterceptor<TContext> Stores domain events to outbox table on save
DomainEventsTransactionInterceptor Dispatches domain events after transaction commit

Repository

Repository<TAggregateRoot>

Generic repository implementation for aggregate roots:

public interface IOrderRepository : IRepository<Order> { }

// Automatically registered via AddLeweeDatabaseServices

Domain Event Dispatching

DomainEventDispatcher

Dispatches domain events from the outbox table via MediatR after successful database transactions.

Query Projections

QueryProjectionService

Service for executing query projections with tracking support.

Database Seeding

IDatabaseSeeder<TDbContext>

Interface for implementing database seeders:

public class MyDbSeeder : IDatabaseSeeder<MyDbContext>
{
    public async Task SeedAsync(MyDbContext context, CancellationToken cancellationToken)
    {
        // Seed data
    }
}

Configuration

Basic Setup

// Without DB Seeder
services
    .AddDbContextFactory<MyDbContext>(options => options.UseSqlServer(connectionString))
    .AddLeweeDatabaseServices<MyDbContext>(typeof(MyDomainEntity).Assembly);

With Database Seeder

services
    .AddDbContextFactory<MyDbContext>(options => options.UseSqlServer(connectionString))
    .AddLeweeDatabaseServicesWithSeeder<MyDbContext, MyDbSeeder>(typeof(MyDomainEntity).Assembly);
services
    .AddDbContextFactory<MyDbContext>((provider, options) =>
    {
        options.UseSqlServer(connectionString);
        options.AddAuditInterceptor(provider);
        options.AddDomainEventInterceptors<MyDbContext>(provider);
    })
    .AddLeweeDatabaseServices<MyDbContext>(typeof(MyDomainEntity).Assembly);

Extension Methods

ApplicationDbContextOptionsBuilderExtensions

Method Purpose
AddAuditInterceptor Adds audit details save changes interceptor
AddDomainEventInterceptors<TContext> Adds domain event save changes and transaction interceptors

EntityTypeBuilderExtensions

Method Purpose
ConfigureSoftDelete Adds global query filter for soft-deleted entities

EntityEntryExtensions

Method Purpose
HasChangedOwnedEntities Checks if owned entities have changed

Sample Usage

See the Pizzeria Store Data project for a complete implementation example.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Lewee.Infrastructure.Data:

Package Downloads
Lewee.IntegrationTests

Package Description

Lewee.Infrastructure.PostgreSQL

Package Description

Lewee.Auth.Infrastructure.Data

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.40.3 61 11/22/2026
0.23.0 354 6/14/2024
0.22.0 286 6/3/2024
0.21.0 310 9/24/2023
0.20.0-alpha.1 121 9/24/2023
0.17.0-alpha.1 186 9/23/2023
0.16.0-alpha.1 186 9/23/2023
0.10.0 296 9/19/2023
0.9.0 293 9/17/2023
0.8.0 317 9/3/2023
0.7.0 338 9/3/2023
0.6.0 294 9/1/2023
0.5.3 330 8/25/2023
0.1.0 362 3/28/2023