Mohd2sh.CleanArchitecture.Core.Infrastructure.Persistence 1.0.1

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

CleanArchitecture.Core.Infrastructure.Persistence

Core infrastructure persistence implementations for Entity Framework Core including unit of work, transactions, criteria extensions, domain event collection, and audit interceptors.

Purpose

This package provides base Entity Framework Core implementations of persistence abstractions including unit of work pattern, transaction management, criteria query extensions, domain event collection, and automatic audit field management. It works with CleanArchitecture.Core.Application to provide a complete persistence foundation for Clean Architecture applications.

Installation

dotnet add package Mohd2sh.CleanArchitecture.Core.Infrastructure.Persistence

Usage

Register Unit of Work

services.AddScoped<IUnitOfWork>(sp => 
    new EfUnitOfWork(sp.GetRequiredService<ApplicationDbContext>()));

Using EfCriteria Extensions

public class ProductRepository
{
    private readonly DbContext _db;
    
    public async Task<PaginatedList<Product>> GetProductsAsync(
        int pageNumber, 
        int pageSize, 
        string? searchTerm)
    {
        var criteria = Criteria<Product>.New()
            .Where(p => searchTerm == null || p.Name.Contains(searchTerm))
            .OrderByAsc(p => p.Name)
            .Skip((pageNumber - 1) * pageSize)
            .Take(pageSize)
            .Build();
        
        var (query, totalCount) = await _db.Set<Product>()
            .ApplyWithCountAsync(criteria);
        
        var items = await query.ToListAsync();
        
        return new PaginatedList<Product>(items, totalCount, pageNumber, pageSize);
    }
}

Domain Event Collection

// After SaveChangesAsync, collect domain events
var domainEvents = _dbContext.CollectAndClear();

// Domain events are automatically cleared from aggregates
// Dispatch events through your event dispatcher
foreach (var domainEvent in domainEvents)
{
    await _domainEventDispatcher.PublishAsync(domainEvent);
}

Auditable Entity Interceptor

// Register the interceptor in your DbContext configuration
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    optionsBuilder.AddInterceptors(new AuditableEntityInterceptor(
        _dateTimeProvider,
        () => _currentUserService.GetCurrentUserId()));
}

// Entities implementing IAuditableEntity will automatically have
// CreatedAt, CreatedBy, LastModifiedAt, LastModifiedBy set

Dependencies

Requires CleanArchitecture.Core.Application and Microsoft.EntityFrameworkCore.

Repository

GitHub: https://github.com/mohd2sh/CleanArchitecture-DDD-CQRS

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 300 11/30/2025