Claudalisk.Dispatching 0.1.0-alpha.4

This is a prerelease version of Claudalisk.Dispatching.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Claudalisk.Dispatching --version 0.1.0-alpha.4
                    
NuGet\Install-Package Claudalisk.Dispatching -Version 0.1.0-alpha.4
                    
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="Claudalisk.Dispatching" Version="0.1.0-alpha.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Claudalisk.Dispatching" Version="0.1.0-alpha.4" />
                    
Directory.Packages.props
<PackageReference Include="Claudalisk.Dispatching" />
                    
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 Claudalisk.Dispatching --version 0.1.0-alpha.4
                    
#r "nuget: Claudalisk.Dispatching, 0.1.0-alpha.4"
                    
#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 Claudalisk.Dispatching@0.1.0-alpha.4
                    
#: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=Claudalisk.Dispatching&version=0.1.0-alpha.4&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Claudalisk.Dispatching&version=0.1.0-alpha.4&prerelease
                    
Install as a Cake Tool

Claudalisk.Dispatching

The in-process dispatcher. AddClaudaliskDispatching finds the IHandler<,> and IValidator<> classes of every module assembly and registers them as scoped services. IDispatcher.SendAsync runs a message through the pipeline and into its handler. A message's name ends in Command or Query.

Pipeline order

Every IPipelineStep states an Order. The dispatcher sorts steps by it, and steps with equal orders keep their registration order. When the step was registered no longer matters.

Order Step
PipelineOrder.Logging (1000) logging
PipelineOrder.Validation (2000) validation
PipelineOrder.Retry (3000) the dispatcher's retry; no step may use it
PipelineOrder.UnitOfWork (4000) the unit of work (commands only)
5000 the jobs library

Steps below Retry are outer steps and run once, in the caller's scope. Steps above it are inner steps and run inside each attempt. The startup check rejects a step whose order equals PipelineOrder.Retry.

Retry

A command that loses a concurrency race is sent again. The retry applies only when all of these hold:

  • the message is a command
  • no other send is running (it is not a nested send)
  • no unit of work is active in the caller's scope (IUnitOfWork.IsActive is false)

Outer steps run once. Then each attempt, the first included, gets a fresh scope from IServiceScopeFactory, runs the inner steps and resolves the handler there. The attempt scope is disposed afterwards; a failure while disposing it is logged at Warning and does not change the attempt's outcome.

Because every attempt runs in a fresh scope, scoped state the caller prepared is not visible to the handler: values that middleware put into a scoped holder (the current user or tenant) or anything set on a scoped service before sending. Resolve such state from a singleton or an accessor such as IHttpContextAccessor, or pass it in the message. Sends made by the handler go through the attempt scope's dispatcher as nested sends and are not retried on their own.

An attempt is repeated only when it throws ConcurrencyConflictException itself (not wrapped) and the token is not canceled. There is no delay. DispatchingOptions.ConcurrencyAttempts (default 3, at least 1) is the total number of attempts; after the last one the exception propagates. Each retry is logged at Information.

A command sent while a unit of work is active, for example inside IUnitOfWork.RunAsync, joins it: the caller's scope, no retry. Queries are never retried.

One send at a time

Sends in one scope run one at a time. A send that starts while another send of the same scope is running, whether top-level or from inside a handler (Task.WhenAll of two sends), throws InvalidOperationException. Await each send before the next. The check is atomic.

Outer steps without a handler

IOuterPipeline.RunAsync(message, kind, inner) runs the outer steps for a message, then inner, in the current scope. There is no retry, unit of work or inner step. It counts as a send, so sends from inside inner are nested. The kind is given explicitly and may be MessageKind.Event.

Validators

Validation is by exact type: only the IValidator<T> registered for the message's own type runs. A validator for a base type or an interface does not run. Failures are collected into one MessageValidationException with camelCase keys.

Startup check

ValidateDispatching and the hosted startup check build the registry and throw one InvalidOperationException listing every problem:

  • a singleton handler
  • a message with several handlers
  • a handler for a message whose name ends in neither Command nor Query
  • a keyed IHandler<,> registration; the dispatcher resolves handlers without a key
  • a public class, struct or nested type of a module contract assembly named ...Command or ...Query without a handler
  • an assembly whose types cannot be loaded, with the first loader messages

A pipeline step with Order equal to PipelineOrder.Retry is rejected when the hosted startup check or ValidateDispatching runs, and again when a scope's dispatcher is created. The registry itself never constructs steps.

The registry reads the service collection once, when the provider first builds it, and keeps no reference to the collection afterwards. A handler or validator in a module assembly that was added to the catalog after AddClaudaliskDispatching is found at that moment and created per send with ActivatorUtilities. It is disposed (IAsyncDisposable first, else IDisposable) when the send, or the validation, completes.

Logging

Each send logs at Debug. A canceled send logs at Debug, a validation failure at Information without the exception, and any other failure at Information with it.

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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Claudalisk.Dispatching:

Package Downloads
Claudalisk.Jobs

Queued work as jobs: queueing in the unit of work, workers with retries, heartbeats, cancel and progress, batch jobs, event fan-out and the jobs router.

Claudalisk.Scheduling

Cron schedules from configuration that queue commands as jobs of the scheduler's own jobs module, once per scheduled time.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0-alpha.5 91 11/24/2026
0.1.0-alpha.4 161 11/22/2026
0.1.0-alpha.3 83 11/22/2026
0.1.0-alpha.2 78 11/21/2026
0.1.0-alpha.1 670 11/8/2026