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
<PackageReference Include="Lewee.Infrastructure.Data" Version="0.40.3" />
<PackageVersion Include="Lewee.Infrastructure.Data" Version="0.40.3" />
<PackageReference Include="Lewee.Infrastructure.Data" />
paket add Lewee.Infrastructure.Data --version 0.40.3
#r "nuget: Lewee.Infrastructure.Data, 0.40.3"
#:package Lewee.Infrastructure.Data@0.40.3
#addin nuget:?package=Lewee.Infrastructure.Data&version=0.40.3
#tool nuget:?package=Lewee.Infrastructure.Data&version=0.40.3
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 abstractionsMediatR- For domain event notification dispatchingMicrosoft.EntityFrameworkCore- ORM frameworkMicrosoft.EntityFrameworkCore.Relational- Relational database supportMicrosoft.Extensions.Configuration.Binder- Configuration bindingMicrosoft.Extensions.DependencyModel- Assembly scanningMicrosoft.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);
With Interceptors (recommended)
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Lewee.Domain (>= 0.40.3)
- MediatR (>= 12.5.0)
- Microsoft.EntityFrameworkCore (>= 11.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 11.0.0)
- Microsoft.Extensions.DependencyModel (>= 11.0.0)
- Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore (>= 11.0.0)
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 |