Franz.Common.EntityFramework 2.1.1

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

๐Ÿ“ฆ Franz.Common.EntityFramework

A core infrastructure library of the Franz Framework, designed to extend and simplify Entity Framework Core integration in .NET systems.

It provides a pragmatic persistence layer, supporting:

  • Domain-Driven Design (selectively applied)
  • CQRS architectures
  • Soft deletes + auditing
  • Event-driven persistence patterns
  • DI-driven modular design

Unlike strict DDD implementations, this library follows a system-first pragmatic architecture, where domain purity is preserved only where it adds value.


๐Ÿš€ Version

v2.1.1


๐Ÿง  Architectural Philosophy

This library is built on a pragmatic DDD enforcement model:

DDD is applied where it improves domain correctness, not as a global constraint.

Core principles:

  • Persistence is EF-native, not domain-driven
  • Repositories are identity-agnostic (IEntity)
  • Domain identity (Entity<TId>) is isolated from persistence contracts
  • DI is explicit and convention-based
  • Infrastructure is optimized for scalability over theoretical purity

๐Ÿงฑ Core Concepts


1. DbContextBase (Canonical EF Context)

The base DbContext provides:

โœ” Built-in Features

  • Auditing (CreatedBy, CreatedOn, etc.)
  • Soft deletes (IsDeleted, DeletedOn, DeletedBy)
  • Global query filters
  • Domain event dispatching via IDispatcher
  • Current user tracking integration

๐Ÿ“Œ Example

public class AppDbContext : DbContextBase
{
    public AppDbContext(
        DbContextOptions<AppDbContext> options,
        IDispatcher dispatcher,
        ICurrentUserService currentUser)
        : base(options, dispatcher, currentUser)
    {
    }

    public DbSet<Order> Orders => Set<Order>();

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.ApplyConfigurationsFromAssembly(GetType().Assembly);
    }
}

๐Ÿง  Behavior Summary

  • Automatically applies auditing on SaveChanges
  • Converts deletes into soft deletes
  • Filters deleted entities globally
  • Dispatches domain events after persistence

2. Repository System (Pragmatic Model)

The repository system is intentionally simplified for scalability.


๐Ÿ“ฆ EntityRepository (CRUD)

public class EntityRepository<TDbContext, TEntity>
    where TDbContext : DbContext
    where TEntity : class, IEntity

โœ” Responsibilities:

  • CRUD operations
  • EF Core persistence
  • Soft delete compliance
  • No domain logic
  • No identity assumptions

๐Ÿ“Œ Example

public class OrderRepository 
    : EntityRepository<AppDbContext, Order>
{
    public OrderRepository(AppDbContext dbContext) 
        : base(dbContext) { }
}

๐Ÿง  Key Design Rule

Repositories do NOT manage identity.

Identity is handled by:

  • IEntity.GetId()
  • EF Core key resolution
  • Domain layer (Entity<TId>)

๐Ÿ“ฆ AggregateRepository (Event-Sourced)

Used for event-driven aggregates.

public class AggregateRepository<TDbContext, TAggregateRoot, TEvent>

โœ” Responsibilities:

  • Event sourcing persistence
  • Aggregate rehydration
  • Event storage coordination
  • Domain event consistency

3. Auditing System

All entities implementing Entity<TId> automatically support:

  • CreatedOn, CreatedBy
  • LastModifiedOn, LastModifiedBy
  • DeletedOn, DeletedBy
  • IsDeleted soft delete flag

โœ” Behavior

  • Automatically applied on SaveChanges
  • Fully transparent to application layer
  • No manual intervention required

4. Soft Delete System

Instead of physical deletion:

DELETE โ†’ UPDATE IsDeleted = true

โœ” Features:

  • Global EF query filter
  • Automatic exclusion of deleted entities
  • Audit trail preserved

5. Domain Events Integration

DbContext automatically dispatches domain events via:

IDispatcher

โœ” Lifecycle:

  1. Entity changes tracked
  2. SaveChanges executed
  3. Events collected
  4. Dispatcher publishes after commit

6. Entity Framework Conventions

โœ” Supported entity model

public abstract class Entity<TId> : IEntity

โœ” Characteristics:

  • Strongly typed identity (TId)
  • EF-compatible mapping
  • Audit support (via DbContext)
  • Soft delete support

โœ” Identity rules

  • Identity is defined in the domain (Entity<TId>)
  • Repositories are identity-agnostic
  • EF resolves identity via object[] keys

7. Dependency Injection Model

This framework uses explicit DI discovery.


โœ” Auto-registration rules

Only services implementing:

  • IScopedDependency
  • ISingletonDependency

are automatically registered.


โœ” Benefits

  • No hidden service locator
  • Fully deterministic composition
  • Explicit module boundaries
  • Scalable modular architecture

8. Configuration Extensions

โœ” Register EF Infrastructure

services.AddEntityFrameworkFranz();

Includes:

  • DbContextBase support
  • repositories
  • auditing pipeline
  • DI wiring

โš ๏ธ Design Constraints

โŒ Do NOT

  • Inject identity logic into repositories
  • Use repository-level TId constraints
  • Bypass Entity<TId> model
  • Perform manual auditing

โœ” Always

  • Let EF handle persistence
  • Let domain handle identity
  • Use repositories as orchestration layer only
  • Use DI markers for registration

๐Ÿงญ Architecture Overview

Domain Layer
 โ”œโ”€โ”€ Entity<TId>
 โ”œโ”€โ”€ Domain Events
 โ”œโ”€โ”€ Aggregates

Application Layer
 โ”œโ”€โ”€ CQRS / Mediator

Infrastructure Layer
 โ”œโ”€โ”€ DbContextBase
 โ”œโ”€โ”€ EntityRepository
 โ”œโ”€โ”€ AggregateRepository

EF Core Layer
 โ”œโ”€โ”€ DbSet<TEntity>
 โ”œโ”€โ”€ ChangeTracker
 โ”œโ”€โ”€ Global Filters

DI Layer
 โ”œโ”€โ”€ IScopedDependency
 โ”œโ”€โ”€ IServiceCollection extensions

๐Ÿงช Version History

v2.0.3 โ€“ Pragmatic Architecture Alignment

๐Ÿง  Major Changes

  • Replaced identity-coupled repositories with IEntity-based model
  • Removed TId dependency from repository contracts
  • Standardized EF Core identity resolution via object
  • Introduced explicit DI-based service discovery model
  • Reinforced pragmatic DDD enforcement strategy

โš™๏ธ Improvements

  • Reduced repository complexity
  • Simplified DI wiring
  • Improved EF Core compatibility
  • Strengthened infrastructure scalability

โš ๏ธ Design Trade-off

  • Reduced compile-time identity enforcement in repositories
  • Identity safety moved to domain layer (Entity<TId>)

๐Ÿ“Œ Summary

Franz.Common.EntityFramework v2.0.3 provides:

โœ” EF-native persistence layer โœ” Pragmatic DDD enforcement โœ” Scalable repository abstraction โœ” Auditing + soft delete system โœ” Event-driven persistence support โœ” DI-driven modular architecture


๐Ÿง  Final Statement

This library prioritizes system scalability and architectural clarity over theoretical purity, applying DDD only where it improves correctness, not as a global constraint.


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 (9)

Showing the top 5 NuGet packages that depend on Franz.Common.EntityFramework:

Package Downloads
Franz.Common.EntityFramework.MariaDB

Shared utility library for the Franz Framework.

Franz.Common.EntityFramework.SQLServer

Shared utility library for the Franz Framework.

Franz.Common.EntityFramework.PostGres

Shared utility library for the Franz Framework.

Franz.Common.MongoDB

Shared utility library for the Franz Framework.

Franz.Common.SSO

Shared utility library for the Franz Framework.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.1 86 4/22/2026
2.0.2 166 3/30/2026
2.0.1 155 3/29/2026
1.7.8 165 3/2/2026
1.7.7 183 1/31/2026
1.7.6 183 1/22/2026
1.7.5 185 1/10/2026
1.7.4 175 12/27/2025
1.7.3 262 12/22/2025
1.7.2 249 12/21/2025
1.7.1 202 12/20/2025
1.7.0 353 12/16/2025
1.6.21 267 11/27/2025
1.6.20 279 11/24/2025
1.6.19 271 10/25/2025
1.6.15 304 10/20/2025
1.6.14 312 10/15/2025
1.6.3 306 10/9/2025
1.6.2 296 10/7/2025
1.5.9 315 9/24/2025
Loading failed