Franz.Common.Business 2.2.15

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

๐Ÿ“ฆ Franz.Common.Business

A core infrastructure library of the Franz Framework, designed to support Domain-Driven Design (DDD), CQRS, and Event-Sourcing-ready architectures in modern .NET applications.

It provides a clean, deterministic, and production-grade foundation for building scalable business systems with strong separation of concerns.


๐Ÿš€ Version

Current Version: v2.2.15


๐Ÿง  Core Philosophy

Franz.Common.Business enforces the following principles:

  • Identity is factory-controlled
  • Domain logic is persistence-agnostic
  • Repositories are storage-only abstractions
  • Entities are immutable in identity after creation
  • DI is deterministic and explicit
  • No hidden service locator or runtime DI construction

โœจ Key Features


1. Domain Model (DDD Core)

โœ” Entity Model

All domain entities derive from a unified base:

public abstract class Entity<TId> : IEntity
{
    public TId Id { get; private set; } = default!;

    protected Entity() { }

    protected Entity(TId id)
    {
        Id = id;
    }

    public object GetId() => Id!;
}

โœ” Key characteristics:

  • Strongly typed identity (Guid or int)
  • Factory-controlled identity assignment
  • Immutable identity after creation
  • Equality based on identity
  • EF Core compatible design

2. Identity System

โœ” Supported ID strategies

  • Guid V7 (default standard)
  • int (database-generated identities)

โœ” Centralized ID generation

public interface IIdGenerator<TId>
{
    TId Create();
}

โœ” Default implementation:

public sealed class GuidV7Generator : IIdGenerator<Guid>
{
    public Guid Create() => Guid.CreateVersion7();
}

3. Entity Factories

Entities must be created through controlled factories.

public interface IEntityFactory<TId, TEntity>
    where TEntity : Entity<TId>
{
    TEntity Create();
}

โœ” Responsibilities:

  • Generate entity identity via IIdGenerator<TId>
  • Ensure consistent creation rules
  • Enforce domain construction invariants
  • Prevent identity bypass (e.g. new Entity() misuse)

โœ” Implementation: EntityFactory<TKey, TEntity>

The default implementation uses a compiled expression tree delegate, cached statically per closed generic type, to invoke the entity's protected constructor with zero reflection overhead after startup.

public sealed class EntityFactory<TKey, TEntity> : IEntityFactory<TKey, TEntity>
    where TEntity : Entity<TKey>
{
    public TEntity Create() => _activator(_idGenerator.Create());
}
How it works
Concern Mechanism
Constructor discovery BindingFlags.NonPublic \| Public โ€” resolves protected constructors
Delegate compilation Expression.Lambda<Func<TKey, TEntity>>(...).Compile()
Caching Static field โ€” compiled once per TEntity type, shared for the application lifetime
Null guard ArgumentNullException.ThrowIfNull on the injected IIdGenerator<TKey>
Misconfiguration Throws TypeInitializationException with an actionable inner message if the required constructor is absent
Eager validation EntityFactory<TKey, TEntity>.Validate() triggers the static constructor at DI registration time
Required entity constructor

Every entity must expose a constructor accepting its key type:

public class Order : Entity<Guid>
{
    protected Order(Guid id) : base(id) { }
}
Eager validation at startup

Call Validate() from your DI registration extension to surface misconfigured entity types immediately, rather than on first use:

services.AddSingleton<IEntityFactory<Guid, Order>, EntityFactory<Guid, Order>>();
EntityFactory<Guid, Order>.Validate();

4. Aggregate Factories

Aggregate roots follow the same factory pattern via AggregateFactory<TAggregate, TEvent>.

public interface IAggregateFactory<TAggregate>
{
    TAggregate Create();
}

โœ” Implementation: AggregateFactory<TAggregate, TEvent>

Mirrors EntityFactory exactly โ€” compiled delegate, static cache, fail-fast error messages, and eager validation support โ€” but is scoped to AggregateRoot<TEvent> and hardcoded to Guid identity, consistent with the event-sourcing model.

public sealed class AggregateFactory<TAggregate, TEvent> : IAggregateFactory<TAggregate>
    where TAggregate : AggregateRoot<TEvent>
    where TEvent : IEvent
{
    public TAggregate Create() => _activator(_idGenerator.Create());
}
Required aggregate constructor
public class OrderAggregate : AggregateRoot<OrderEvent>
{
    protected OrderAggregate(Guid id) : base(id) { }
}
Eager validation at startup
services.AddSingleton<IAggregateFactory<OrderAggregate>, AggregateFactory<OrderAggregate, OrderEvent>>();
AggregateFactory<OrderAggregate, OrderEvent>.Validate();

5. Repositories (Persistence Layer)

Repositories are identity-agnostic and persistence-only abstractions.

public interface IEntityRepository<TEntity>
    where TEntity : class, IEntity
{
    Task<TEntity> GetByIdAsync(object id, CancellationToken cancellationToken = default);
    Task AddAsync(TEntity entity, CancellationToken cancellationToken = default);
    Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default);
    Task DeleteAsync(TEntity entity, CancellationToken cancellationToken = default);
}

โœ” Design principles:

  • No dependency on TId
  • No domain logic
  • EF Core handles identity resolution
  • Supports both Guid and int primary keys

6. Aggregates & Event Sourcing

โœ” Aggregate Root

Supports event-driven state mutation:

public abstract class AggregateRoot<TEvent> : Entity<Guid>
    where TEvent : IEvent
{
    protected void RaiseEvent(TEvent @event) { }
    public void ReplayEvents(IEnumerable<TEvent> events) { }
    public void Rehydrate(Guid id, IEnumerable<TEvent> events) { }
}

โœ” Features:

  • Event-based state changes
  • Automatic version tracking
  • Uncommitted event collection
  • Full rehydration support

7. Domain Events

All events implement:

public interface IDomainEvent : IEvent
{
    Guid EventId { get; }
    DateTimeOffset OccurredOn { get; }
    string? CorrelationId { get; }
    Guid? AggregateId { get; }
    string AggregateType { get; }
    string EventType { get; }
}

โœ” Benefits:

  • Full auditability
  • Distributed tracing support
  • Event correlation across services

8. CQRS Support

Built-in support for:

  • Commands (ICommandHandler)
  • Queries (IQueryHandler)
  • Mediator-based execution pipeline

9. Resilience Pipelines

Production-ready pipeline support:

  • Retry
  • Circuit Breaker
  • Timeout
  • Bulkhead Isolation

10. Dependency Injection Bootstrap

โœ” Single entry point:

services.AddBusiness(applicationAssembly);
services.AddBusinessPlatform();

โœ” What it registers:

Domain layer
  • IIdGenerator<Guid>
  • IEntityFactory<,>
  • IAggregateFactory<>
Mediator layer
  • Command/query pipeline
  • Event dispatching
Handler discovery
  • Automatic handler registration

โš ๏ธ Important Design Rules

โŒ Do NOT:

  • Generate IDs manually (Guid.NewGuid())
  • Bypass factories for entity creation
  • Define entities without a protected T(TKey id) constructor
  • Use service locator inside startup/configuration
  • Introduce custom repository identity types

โœ” Always:

  • Use factories for entity creation
  • Use IIdGenerator<TId> for identity
  • Define the required single-parameter constructor on every entity and aggregate
  • Call Validate() at DI registration time to catch constructor mismatches at startup
  • Treat repositories as persistence-only abstractions

๐Ÿงฉ Architecture Overview

Domain Layer
    โ”œโ”€โ”€ Entities (Entity<TId>)
    โ”œโ”€โ”€ Aggregates (AggregateRoot<TEvent>)
    โ”œโ”€โ”€ Value Objects
    โ””โ”€โ”€ Domain Events

Factory Layer
    โ”œโ”€โ”€ IEntityFactory<TId, TEntity>      โ†’ EntityFactory<TKey, TEntity>
    โ””โ”€โ”€ IAggregateFactory<TAggregate>     โ†’ AggregateFactory<TAggregate, TEvent>

Identity Layer
    โ””โ”€โ”€ IIdGenerator<TId>

Persistence Layer
    โ””โ”€โ”€ IEntityRepository<TEntity>

Application Layer
    โ””โ”€โ”€ CQRS + Mediator

Bootstrap Layer
    โ””โ”€โ”€ AddBusiness()

๐Ÿงช Version History

v2.2.09 โ€“ Factory Hardening

  • Replaced reflection-on-every-call pattern with compiled expression tree delegates in both EntityFactory and AggregateFactory
  • Delegates are compiled once per closed generic type and cached in a static field for the application lifetime โ€” near-native instantiation performance
  • Removed the injected Func<Guid, TAggregate> activator from AggregateFactory โ€” the factory now owns constructor resolution entirely, eliminating a class of registration-site errors
  • Added TypeInitializationException with a descriptive inner message when the required single-parameter constructor is absent, replacing the previous opaque CLR failure
  • Added ArgumentNullException.ThrowIfNull guard on injected IIdGenerator<TKey> instances
  • Added static Validate() method to both factories โ€” call at DI registration time to surface misconfigured types at startup rather than on first use
  • Removed unused System.Collections.Concurrent, System.Collections.Generic, and System.Text imports from factory files

v2.0.3 โ€“ Architecture Stabilization

  • Enforced factory-driven identity model
  • Removed mutable identity assignment (SetId eliminated)
  • Introduced immutable entity identity lifecycle
  • Simplified repository abstraction (identity-agnostic)
  • Consolidated DI bootstrap into single deterministic entry point
  • Removed ServiceProvider creation from configuration pipeline
  • Improved EF Core compatibility and consistency
  • Strengthened DDD alignment across domain layer

๐Ÿ“Œ Summary

Franz.Common.Business v2.2.13 provides a:

โœ” deterministic โœ” factory-driven โœ” EF Core compatible โœ” DDD-aligned โœ” CQRS-ready

foundation for enterprise-grade .NET applications.


๐Ÿง  Final Note

This library enforces architectural discipline by design, not convention.

It ensures that:

  • identity is always controlled
  • domain logic remains pure
  • persistence remains isolated
  • system composition is deterministic
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 (8)

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

Package Downloads
Franz.Common.Serialization

Shared utility library for the Franz Framework.

Franz.Common.Messaging

Shared utility library for the Franz Framework.

Franz.Common.EntityFramework

Shared utility library for the Franz Framework.

Franz.Common.Bootstrap

Shared utility library for the Franz Framework.

Franz.Common.MongoDB

Shared utility library for the Franz Framework.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.2.15 0 6/29/2026
2.2.14 0 6/29/2026
2.2.13 0 6/29/2026
2.2.12 0 6/28/2026
2.2.11 7 6/28/2026
2.2.10 33 6/28/2026
2.2.9 70 6/28/2026
2.2.8 75 6/28/2026
2.2.7 464 6/7/2026
2.2.6 468 6/6/2026
2.2.5 473 6/4/2026
2.2.4 460 6/3/2026
2.2.3 449 6/2/2026
2.2.2 449 6/2/2026
2.2.1 475 5/24/2026
2.1.4 368 4/27/2026
2.1.3 342 4/26/2026
2.1.2 350 4/26/2026
2.1.1 358 4/22/2026
2.0.2 370 3/30/2026
Loading failed