HerrGeneral.Core
1.7.0
dotnet add package HerrGeneral.Core --version 1.7.0
NuGet\Install-Package HerrGeneral.Core -Version 1.7.0
<PackageReference Include="HerrGeneral.Core" Version="1.7.0" />
<PackageVersion Include="HerrGeneral.Core" Version="1.7.0" />
<PackageReference Include="HerrGeneral.Core" />
paket add HerrGeneral.Core --version 1.7.0
#r "nuget: HerrGeneral.Core, 1.7.0"
#:package HerrGeneral.Core@1.7.0
#addin nuget:?package=HerrGeneral.Core&version=1.7.0
#tool nuget:?package=HerrGeneral.Core&version=1.7.0
HerrGeneral.Core
Essential components for application integration, mediator dispatch, open pipeline execution, and command concurrency control.
Registration with Dependency Injection
Herr General integrates seamlessly with .NET's dependency injection system using Microsoft.Extensions.DependencyInjection. Configure the framework in your application startup with a fluent API:
// Add Herr General to your service collection
services.AddHerrGeneral(configuration =>
configuration
// Register write side assembly and namespace for command and domain event handlers
.ScanWriteSideOn(typeof(Person).Assembly, typeof(Person).Namespace!)
// Register in-transaction synchronous projections
.ScanSyncProjectionsOn(typeof(OrderSummarySyncProjection).Assembly)
// Register read side assembly for eventual post-transaction projections
.ScanPostProjectionsOn(typeof(PersonFriendRM).Assembly, typeof(PersonFriendRM).Namespace!)
// Register post-transaction side effects (emails, notifications, external message bus)
.ScanSideEffectsOn(typeof(SendWelcomeEmailSideEffect).Assembly));
Pipeline Behaviors & Extension
Modules and consuming applications can intercept command handling by implementing ICommandPipelineBehavior<TCommand, TResult> and optional IOrderedPipelineBehavior:
public class AuditBehavior<TCommand, TResult> : ICommandPipelineBehavior<TCommand, TResult>, IOrderedPipelineBehavior
{
public PipelinePhase Phase => PipelinePhase.Security;
public async Task<(IReadOnlyList<object> Events, TResult Result)> HandleAsync(
CommandExecutionContext<TCommand, TResult> context,
CommandHandlerDelegate<TResult> next)
{
// Custom pre-processing
var result = await next();
// Custom post-processing
return result;
}
}
This registration process scans the specified assemblies for command handlers, event handlers, projections, and side-effects, registering them with the appropriate lifetime scopes in the dependency injection container.
Handler Taxonomy & Transaction Boundaries
HerrGeneral organizes handler contracts around the IHandle... convention:
IHandleSyncProjection<in TEvent>:- Executes inside the active
IUnitOfWorktransaction beforeCommit(). - Ideal for strict consistency projections (e.g. SQL read models in the same database) or transactional outbox tables.
- Throws and triggers
RollBack()if an exception occurs.
- Executes inside the active
IHandlePostProjection<in TEvent>:- Executes strictly after
IUnitOfWork.Commit()succeeds. - Ideal for eventual consistency projections and search indexes.
- Exceptions are captured by
CommandExecutionTracerand logged without affecting the committed transaction.
- Executes strictly after
IHandleSideEffect<in TEvent>:- Executes strictly after
IUnitOfWork.Commit()succeeds. - Ideal for fire-and-forget side effects, emails, external webhooks, and message publishing.
- Exceptions are captured and isolated by
CommandExecutionTracer.
- Executes strictly after
Mediator
Send your commands with the mediator:
var mediator = serviceProvider.GetRequiredService<Mediator>();
var result = await mediator.Send(new MyCommand());
Command Concurrency & Partition-Based Locking
HerrGeneral features a built-in CommandConcurrencyLimiter that ensures commands targeting the same aggregate or partition are serialized while allowing independent aggregates to execute concurrently.
Declarative Attribute Locking (Recommended)
Decorate the identifier property of your command with [LockKey<TAggregate>] (or [LockKey(typeof(TAggregate))]):
using HerrGeneral.WriteSide;
public record CancelOrder(
[property: LockKey<Order>] Guid OrderId,
string Reason
);
Commands with the same (typeof(Order), OrderId) lock key are processed sequentially. Commands with different IDs or different aggregate types execute concurrently.
Interface-Based Locking (Extension Point)
For complex, dynamic, or composite partition keys, implement IKeyedCommand:
using HerrGeneral.WriteSide;
public record ProcessPayment(Guid TenantId, Guid AccountId, decimal Amount) : IKeyedCommand
{
public object Key => (TenantId, typeof(Account), AccountId);
}
External Handler Integration
Herr General provides a comprehensive set of configuration methods to integrate existing handlers or third-party components that don't follow the standard conventions. This flexibility is essential when working with legacy systems or external libraries.
Command Handler Integration Methods
The Configuration class offers several methods to adapt different types of external command handlers:
1. Simple Command Handler Registration
For handlers that already return events in the expected format (IEnumerable<object>):
services.UseHerrGeneral(config =>
config.MapCommandHandler<MyCommand, ExternalCommandHandler>());
How it works:
- Registers
ExternalCommandHandleras the handler forMyCommand - The handler's return value is used directly as the event collection
- Suitable for handlers that already return a collection of events
2. Command Handler with Event Mapping
For handlers that return a custom result type that needs transformation:
services.UseHerrGeneral(config =>
config.MapCommandHandler<MyCommand, ExternalCommandHandler, CustomResult>(
// Transform function: converts the handler result into events
result => result.MyEvents
));
How it works:
- The handler returns a custom type (
CustomResult) - The provided mapping function transforms this result into a collection of events
- Enables integration with handlers that don't directly produce events
3. Command Handler with Value Return
For handlers that need to produce both events and a specific return value (especially useful for creation commands):
services.UseHerrGeneral(config =>
config.MapCommandHandler<CreateEntity, ExternalCreateHandler, CustomResult, Guid>(
// Event mapping function
result => result.MyEvents,
// Value mapping function
result => result.Id // Returns the ID to the caller
));
How it works:
- The first function maps the handler result to domain events
- The second function extracts a specific value from the result to return to the caller
- Perfect for creation commands where you need to return the new entity's ID
- The extracted value is wrapped in a
Result<TValue>for consistent error handling
Event Handler Integration
Event handlers can also be externally registered for both write and read sides:
Write Side Event Handlers
services.UseHerrGeneral(config =>
config.MapEventHandlerOnWriteSide<PaymentReceived, UpdateAccountBalanceHandler>());
Purpose: Register handlers that perform domain logic in response to events (may generate additional events).
Read Side Event Handlers
services.UseHerrGeneral(config =>
config.MapEventHandlerOnReadSide<OrderShipped, UpdateShippingStatisticsHandler>());
Purpose: Register handlers that update read models and projections (should not produce new events).
Domain Exception Registration
Herr General distinguishes between technical failures and business rule violations by registering domain exceptions:
services.UseHerrGeneral(config =>
config.UseDomainException<InsufficientFundsException>());
Benefits:
- Registered exceptions are treated as expected business outcomes rather than system errors
- They are automatically wrapped in a
DomainErrorresult instead of anExceptionresult - Provides a cleaner separation between technical failures and business rule violations
Diagnostic Logging & Causal Tree Tracing
HerrGeneral includes a structured causal tree formatter (ActivityTreeFormatter) that logs the hierarchical execution path of every command when logging is enabled (LogLevel.Information or LogLevel.Debug):
CMD [ProcessCardPayment] (thread #12) ............................. [OK] (16.2ms)
|
\--> (cmd) ProcessCardPaymentHandler (0.8ms)
|
|-- (evt) CardPaymentAuthorized
| \--> (wr) DebitAccountOnCardPayment (2.3ms)
| \-- (evt) AccountDebited
| \--> (wr) ApplyOverdraftFeeOnAccountDebited (1.4ms)
| \-- (evt) FeeApplied
|
\== [TX COMMIT] (1.1ms)
|
+-- [SYNC PROJECTIONS] (Read-Side)
| |-- CardPaymentAuthorized ===> CardTransactionsView (1.8ms)
| |-- AccountDebited ===> AccountBalanceView (2.1ms)
| \-- FeeApplied ===> AccountStatementView (1.2ms)
|
\-- [POST TRANSACTION] (Side Effects & Outbox)
|-- CardPaymentAuthorized ===> SendSmsConfirmation (2.4ms)
\-- FeeApplied ===> SendOverdraftWarning (2.0ms)
| 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
- HerrGeneral.Primitives (>= 1.7.0)
- HerrGeneral.ReadSide (>= 1.7.0)
- HerrGeneral.WriteSide (>= 1.7.0)
- Microsoft.Extensions.DependencyInjection (>= 10.0.12)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.12)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on HerrGeneral.Core:
| Package | Downloads |
|---|---|
|
HerrGeneral.Test.Extension
Helper methods for HerrGeneral testing |
|
|
HerrGeneral.Core.DDD
Domain-Driven Design (DDD) aggregate lifecycle and dynamic handler integration for HerrGeneral |
|
|
HerrGeneral.OpenTelemetry
OpenTelemetry instrumentation extensions for HerrGeneral CQRS library |
|
|
HerrGeneral.Testing
Testing utilities and fluent assertion extensions for HerrGeneral CQRS applications |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.7.0 | 109 | 10/7/2026 |
| 1.6.0 | 114 | 10/5/2026 |
| 1.5.1-alpha.0.30 | 68 | 10/5/2026 |
| 1.3.0 | 762 | 12/1/2025 |
| 1.2.1-alpha.0.2 | 432 | 11/30/2025 |
| 1.0.1-alpha.0.3 | 403 | 11/20/2025 |
| 0.1.26-rc | 348 | 11/11/2025 |
| 0.1.25-rc | 268 | 9/25/2025 |
| 0.1.24-rc | 216 | 9/12/2025 |
| 0.1.23-rc | 264 | 9/11/2025 |
| 0.1.22-rc | 250 | 9/11/2025 |
| 0.1.21-rc | 174 | 8/23/2025 |
| 0.1.20-rc | 328 | 8/7/2025 |
| 0.1.19-rc | 337 | 8/6/2025 |
| 0.1.18-rc | 154 | 8/1/2025 |
| 0.1.17-rc | 249 | 7/13/2025 |
| 0.1.16-rc | 186 | 7/4/2025 |
| 0.1.15-rc | 265 | 7/1/2025 |
| 0.1.14-rc | 208 | 6/28/2025 |
| 0.1.13-rc | 200 | 11/12/2024 |