Despro.Framework.Infrastructure 2.2.1

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

Despro.Framework.Infrastructure

The infrastructure layer of Despro Framework.

Despro.Framework.Infrastructure provides the concrete implementations of the contracts declared in Despro.Framework.Base: EF Core + Dapper data access, the Unit of Work, JWT-claim-based authentication, error logging, deferred MongoDB audit logging, and a custom MediatR notification dispatcher for domain events. It is the composition root that wires these services into the DI container.

  • Package: Despro.Framework.Infrastructure
  • Version: 2.1.3
  • Target framework: net10.0
  • Depends on: Despro.Framework.Base

Installation

dotnet add package Despro.Framework.Infrastructure

DI registration

using System.Reflection;
using Despro.Framework.Infrastructure;

builder.Services.AddFrameworkInfrastructure(
    builder.Configuration,
    useCaseAssembly: Assembly.GetExecutingAssembly(), // assembly containing your commands
    queryAssembly:   Assembly.GetExecutingAssembly(), // assembly containing your queries
    MongoDbLog: true);                                // false → no-op logging

AddFrameworkInfrastructure registers:

  • IAuthService → AuthService, IErrorLogger → ErrorLogger
  • IUnitOfWork → UnitOfWork, IBaseRepository<> → Repository<>, IRepositoryServices → RepositoryServices
  • ICustomPublisher → CustomPublisher
  • MediatR (scanning CustomPublisher's assembly plus your useCaseAssembly / queryAssembly) and their FluentValidation validators
  • When MongoDbLog: true: IMongoClient/IMongoDatabase (from MongoDbConfig:ConnectionString — throws if missing), ILogService → MongoLogService, ILoggingContext → LoggingContext
  • When MongoDbLog: false: ILogService → NullLogService, ILoggingContext → NullLoggingContext

Key components

Data access (BaseServices, Contexts)

Type Role
EfBaseContext Abstract DbContext base. Applies a global soft-delete query filter (!IsDelete) to every BaseEntity, forces DeleteBehavior.Restrict on non-owned FKs, applies IEntityTypeConfiguration from a supplied assembly, names tables by CLR type, and dispatches queued domain events on SaveChangesAsync. Exposes DbSet<SystemError>.
BaseRepository<TEntity> / Repository<TEntity> Generic EF Core repository (IBaseRepository<>). Applies audit stamps automatically and queues an audit log entry on write.
DapperRepository<TEntity> IDapperRepository<> — raw SQL, expression-to-WHERE translation, paging, stored procedures (including output params).
DapperContext Creates SqlConnections for Dapper.
UnitOfWork IUnitOfWork over EfBaseContext; flushes pending audit logs after SaveChanges(Async) and manages transactions (ExecuteTransactionAsync, …).
RepositoryServices Aggregates IAuthService, ILoggingContext and IServiceProvider for the repositories.

Authentication (BaseServices/AuthService)

AuthService implements IAuthService by reading the current HttpContext user's JWT claims (user id, full name, roles, expiry, IP) and provides role-validation guards (CheckRoleValidation, CheckRoleValidationByRoleGuid) that throw AuthException on mismatch.

Error logging (BaseServices/ErrorLogger)

ErrorLogger implements IErrorLogger, serializing exception details (with the acting user and Persian date) to per-day JSON files and building a SystemError record.

Audit logging (InfrastructureServices, InfrastructureModels)

  • LoggingContext (ILoggingContext) buffers log entries in memory and flushes them in batches (BatchSize = 100) to ILogService.
  • MongoLogService (ILogService) persists LogEntity documents to the LogEntries MongoDB collection and provisions indexes on entity name / date / user / log type.
  • NullLogService / NullLoggingContext are the no-op implementations used when MongoDB logging is disabled, so calling code never branches on whether logging is on.
  • LogEntity + OperationLogType (Add/Update/Delete) model the audit records.

Domain-event dispatch (MediatR)

  • ICustomPublisher / CustomPublisher — publishes MediatR notifications with a selectable PublishStrategy (SyncContinueOnException, SyncStopOnException, Async, ParallelNoWait, ParallelWhenAll, ParallelWhenAny).
  • CustomMediator — a Mediator subclass overriding PublishCore to apply the chosen strategy. EfBaseContext uses PublishStrategy.Async to flush AggregateRoot domain events during SaveChangesAsync.

Exceptions (InfrastructureExceptions)

BaseInfrastructureException (abstract), AuthException, BaseRepositoryException.


Configuration

Key When Notes
MongoDbConfig:ConnectionString MongoDbLog: true Required; throws if missing.
MongoDbConfig:DatabaseName MongoDbLog: true Audit-log database.

Usage

Derive your application's DbContext from EfBaseContext:

public class AppDbContext(
    DbContextOptions<AppDbContext> options,
    ICustomPublisher publisher)
    : EfBaseContext(options, publisher, typeof(AppDbContext).Assembly)
{
    public DbSet<Product> Products => Set<Product>();
}

Then inject IBaseRepository<Product> and IUnitOfWork into your handlers — audit stamps, soft-delete filtering, audit logging and domain-event dispatch are handled for you.


Project structure

Despro.Framework.Infrastructure
├── BaseServices/            # AuthService, Repository, UnitOfWork, ErrorLogger
│   ├── DbServices/          # DapperRepository
│   ├── DIContainer/         # RepositoryServices
│   └── IDIContainer/        # IRepositoryServices
├── Contexts/                # EfBaseContext, DapperContext
├── InfrastructureExceptions/# AuthException, BaseRepositoryException
├── InfrastructureIServices/ # ILogService, ILoggingContext
├── InfrastructureModels/    # LogEntity, OperationLogType
├── InfrastructureServices/  # LoggingContext, MongoLogService, Null* (no-op)
├── MediatR/                 # ICustomPublisher, CustomPublisher, CustomMediator, PublishStrategy
└── FrameworkInfrastructureDi.cs # AddFrameworkInfrastructure
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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
2.2.1 95 9/8/2026
2.2.0 108 8/31/2026
2.1.9 114 8/11/2026
2.1.8 118 8/3/2026
2.1.7 119 7/26/2026
2.1.5 116 7/18/2026
2.1.4 121 7/2/2026
2.1.3 121 7/2/2026