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
<PackageReference Include="Despro.Framework.Infrastructure" Version="2.2.1" />
<PackageVersion Include="Despro.Framework.Infrastructure" Version="2.2.1" />
<PackageReference Include="Despro.Framework.Infrastructure" />
paket add Despro.Framework.Infrastructure --version 2.2.1
#r "nuget: Despro.Framework.Infrastructure, 2.2.1"
#:package Despro.Framework.Infrastructure@2.2.1
#addin nuget:?package=Despro.Framework.Infrastructure&version=2.2.1
#tool nuget:?package=Despro.Framework.Infrastructure&version=2.2.1
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 → ErrorLoggerIUnitOfWork → UnitOfWork,IBaseRepository<> → Repository<>,IRepositoryServices → RepositoryServicesICustomPublisher → CustomPublisher- MediatR (scanning
CustomPublisher's assembly plus youruseCaseAssembly/queryAssembly) and their FluentValidation validators - When
MongoDbLog: true:IMongoClient/IMongoDatabase(fromMongoDbConfig: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) toILogService.MongoLogService(ILogService) persistsLogEntitydocuments to theLogEntriesMongoDB collection and provisions indexes on entity name / date / user / log type.NullLogService/NullLoggingContextare 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 selectablePublishStrategy(SyncContinueOnException,SyncStopOnException,Async,ParallelNoWait,ParallelWhenAll,ParallelWhenAny).CustomMediator— aMediatorsubclass overridingPublishCoreto apply the chosen strategy.EfBaseContextusesPublishStrategy.Asyncto flushAggregateRootdomain events duringSaveChangesAsync.
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 | Versions 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. |
-
net10.0
- Dapper (>= 2.1.79)
- Despro.Framework.Base (>= 2.1.7)
- FluentValidation (>= 12.1.1)
- FluentValidation.DependencyInjectionExtensions (>= 12.1.1)
- MediatR (>= 14.2.0)
- Microsoft.EntityFrameworkCore (>= 10.0.9)
- MongoDB.Driver (>= 3.9.0)
- System.IdentityModel.Tokens.Jwt (>= 8.19.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.