AxisMediator 2.2.0
dotnet add package AxisMediator --version 2.2.0
NuGet\Install-Package AxisMediator -Version 2.2.0
<PackageReference Include="AxisMediator" Version="2.2.0" />
<PackageVersion Include="AxisMediator" Version="2.2.0" />
<PackageReference Include="AxisMediator" />
paket add AxisMediator --version 2.2.0
#r "nuget: AxisMediator, 2.2.0"
#:package AxisMediator@2.2.0
#addin nuget:?package=AxisMediator&version=2.2.0
#tool nuget:?package=AxisMediator&version=2.2.0
AxisMediator — Documentation
An in-process CQRS mediator built on AxisResult — typed commands, queries and streaming queries; a typed pipeline (IAxisPipelineBehavior) with a shared AxisPipelineContext; an ambient IAxisMediator carrying TraceId/OriginId/JourneyId/AxisEntityId/CancellationToken; events flow through AxisBus; observability behaviours plug in from AxisLogger, AxisValidator, AxisTelemetry.
public record CreateOrderCommand(AxisEntityId CustomerId, AxisEntityId ProductId, int Quantity)
: IAxisCommand<CreateOrderResponse>;
public record CreateOrderResponse(AxisEntityId OrderId) : IAxisCommandResponse;
public class CreateOrderHandler(IOrderFactory factory, IUnitOfWork uow)
: IAxisCommandHandler<CreateOrderCommand, CreateOrderResponse>
{
public Task<AxisResult<CreateOrderResponse>> HandleAsync(CreateOrderCommand cmd)
=> factory.CreateAsync(cmd)
.ThenAsync(order => uow.SaveChangesAsync().Map(_ => order))
.MapAsync(order => new CreateOrderResponse(order.OrderId));
}
// at the edge
var result = await mediator.Cqrs.ExecuteAsync<CreateOrderCommand, CreateOrderResponse>(cmd);
Use this page as a map: read the trunk below (~5 min) and jump straight to the detail of the group you need — without reading hundreds of lines.
The trunk (read first)
CQRS in 60 seconds
| Concept | Marker interface | Handler | What runs |
|---|---|---|---|
| Command with no response | IAxisCommand |
IAxisCommandHandler<TCommand> |
Task<AxisResult> |
| Command with a typed response | IAxisCommand<TResponse> (TResponse : IAxisCommandResponse) |
IAxisCommandHandler<TCommand, TResponse> |
Task<AxisResult<TResponse>> |
| Query with a typed response | IAxisQuery<TResponse> (TResponse : IAxisQueryResponse) |
IAxisQueryHandler<TQuery, TResponse> |
Task<AxisResult<TResponse>> |
| Stream query with a typed item | IAxisStreamQuery<TItem> |
IAxisStreamQueryHandler<TQuery, TItem> |
IAsyncEnumerable<TItem> |
| Event (fan-out, fire-and-forget) | IAxisEvent |
IAxisEventHandler<TEvent> |
Task<AxisResult> (per handler) |
→ CQRS — commands, queries, streams, events
The mediator surface
public interface IAxisMediator
{
CancellationToken CancellationToken { get; }
string TraceId { get; }
string? OriginId { get; }
string? JourneyId { get; }
AxisEntityId? AxisEntityId { get; }
IAxisMediatorHandler Cqrs { get; }
}
IAxisMediator is the ambient context for a request. Its properties come from IAxisMediatorContextAccessor (AsyncLocal-backed). The Cqrs property dispatches commands/queries/streams. → The mediator and the accessors
IAxisMediatorHandler — the dispatcher
public interface IAxisMediatorHandler
{
Task<AxisResult> ExecuteAsync<TCommand>(TCommand command);
Task<AxisResult<TResponse>> ExecuteAsync<TCommand, TResponse>(TCommand command);
Task<AxisResult<TResponse>> QueryAsync<TQuery, TResponse>(TQuery query);
IAsyncEnumerable<TItem> StreamAsync<TQuery, TItem>(TQuery query);
}
Four methods, one job: resolve the handler, build the pipeline, run it. A missing handler returns AxisError.NotFound("HANDLER_NOT_FOUND_X"). → Dispatching · IAxisMediatorHandler
Pipelines — IAxisPipelineBehavior
The mediator wraps every request in a pipeline of IAxisPipelineBehaviors (registered in DI as open-generics). Behaviours run outside-in: the first registered behaviour is the outermost wrapper; next() calls the inner one; the handler is innermost. → Pipeline behaviours · Pipeline context
Built-in behaviour — PerformanceBehavior
Opt-in IAxisPipelineBehavior<TRequest, TResponse> that warns when a request exceeds 500ms via IAxisLogger<TRequest>. → PerformanceBehavior
Installation
dotnet add package AxisMediator # the mediator + accessors + dispatcher
dotnet add package AxisMediator.Contracts # marker interfaces (rarely added alone)
The CQRS scanner lives in AxisMediator.DependencyInjection.AddCqrsMediator(assembly).
→ Full guide: Getting started
The map (jump to what you need)
| Group | You want to… | Detail |
|---|---|---|
| CQRS | model commands, queries, streams, events | cqrs.md |
Mediator · IAxisMediator ⭐ |
the ambient context every handler reads | mediator-and-accessors.md |
Dispatcher · IAxisMediatorHandler |
the four ExecuteAsync/QueryAsync/StreamAsync |
dispatching.md |
Pipelines · IAxisPipelineBehavior |
write a cross-cutting behaviour | pipeline-behaviors.md |
| Pipeline context | pass values between behaviours | pipeline-context.md |
| Performance behaviour | the in-box slow-request warning | performance-behavior.md |
| Registration & scanning | AddAxisMediator + AddCqrsMediator(assembly) |
registration.md |
| Why? | the case against MediatR | why-axismediator.md |
| Reference | every member at a glance | api-reference.md |
Start here: Getting started · CQRS · The mediator and the accessors
Fundamentals: Dispatching · IAxisMediatorHandler · Pipeline behaviours · Pipeline context
Reference & extras: Performance behaviour · Registration & scanning · Why AxisMediator? · API reference
Design principles
- CQRS is in the type system.
IAxisCommand,IAxisQuery,IAxisEventsay what they are. Handlers cannot be confused for each other. - Errors are values. Every dispatch returns
AxisResult— even "handler not found" is a typedNotFound. - Ambient context lives in
AsyncLocal.TraceId/OriginId/JourneyId/AxisEntityId/CancellationTokentravel without parameter threading. - Pipelines are open-generic. Behaviours register against
IAxisPipelineBehavior<>/<,>— one registration covers every request type. - No "the mediator does everything". Sending an event is
AxisBus. Validating isAxisValidator. Tracing isAxisTelemetry. The mediator dispatches.
License
Apache 2.0
| 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
- AxisLogger (>= 2.2.0)
- AxisMediator.Contracts (>= 2.2.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on AxisMediator:
| Package | Downloads |
|---|---|
|
AxisMemoryBus
Part of the Axis Framework — an opinionated, ports-and-adapters .NET framework. |
GitHub repositories
This package is not used by any popular GitHub repositories.