Trellis.Mediator
3.0.0-alpha.554
See the version list below for details.
dotnet add package Trellis.Mediator --version 3.0.0-alpha.554
NuGet\Install-Package Trellis.Mediator -Version 3.0.0-alpha.554
<PackageReference Include="Trellis.Mediator" Version="3.0.0-alpha.554" />
<PackageVersion Include="Trellis.Mediator" Version="3.0.0-alpha.554" />
<PackageReference Include="Trellis.Mediator" />
paket add Trellis.Mediator --version 3.0.0-alpha.554
#r "nuget: Trellis.Mediator, 3.0.0-alpha.554"
#:package Trellis.Mediator@3.0.0-alpha.554
#addin nuget:?package=Trellis.Mediator&version=3.0.0-alpha.554&prerelease
#tool nuget:?package=Trellis.Mediator&version=3.0.0-alpha.554&prerelease
Trellis.Mediator
Result-aware pipeline behaviors for Mediator that keep handlers focused on business work.
Installation
dotnet add package Trellis.Mediator
Quick Example
using Mediator;
using Trellis;
using Trellis.Mediator;
public sealed record GetOrderQuery(string Id) : IQuery<Result<string>>, IValidate
{
public IResult Validate() =>
string.IsNullOrWhiteSpace(Id)
? Result.Fail(new Error.InvalidInput(EquatableArray.Create(new FieldViolation(InputPointer.ForProperty(nameof(Id)), ValidationCodes.ValueNotEmpty) { Detail = "Order ID is required." })))
: Result.Ok();
}
builder.Services.AddMediator(opts => opts.ServiceLifetime = ServiceLifetime.Scoped);
builder.Services.AddTrellisBehaviors();
Use ServiceLifetime.Scoped when calling AddMediator(...) in a host with a request scope. The Trellis behaviors are scoped (they depend on per-request services); the Mediator default of Singleton will fail ASP.NET's root-scope validation as soon as the first behavior tries to resolve a scoped dependency.
Key Features
Six parameterless actor-aware bases:
ActorCommandHandler,ActorQueryHandler, directActorResourceCommandHandler/ActorResourceQueryHandler, and indirectActorResourceViaCommandHandler/ActorResourceViaQueryHandler. Override protectedHandle(message, actor[, resource/leaf], token); concrete constructors keep business dependencies only.Static/resource stages share one Actor reference per dispatch; the integral
AuthorizationContextBehaviormakes it available only after all gates succeed and isolates nested/concurrent sends. Via handlers receive the leaf, not owners.The only public handler entry is
Handle(message, token), which requires an authorized dispatch. Test through Mediator withTestActorProviderand fake loaders/business dependencies; no public actor/resource bypass or replacement test seam is provided. Existing accessor-only handlers and provider extensions remain supported.Adds validation, authorization, tracing, logging, and exception behaviors that understand
Result<T>.Tracing is registered but not collected until you call
AddTrellisMediatorInstrumentation()on yourTracerProviderBuilder; without it the handler span is silently never recorded.Short-circuits failures before handlers do unnecessary work.
Unified
ValidationBehaviorcomposesIValidate+ everyIMessageValidator<TMessage>(e.g., theTrellis.FluentValidationadapter) and aggregates failures into one response.Supports resource authorization with explicit or assembly-scanned registration.
AddSharedResourceAuthorization<TMessage, TResource, TId, TResponse>()registers the authorization behavior, authorized-resource accessor, and shared-loader adapter without scanning. RegisterSharedResourceLoaderById<TResource,TId>separately. Existing per-message loaders are preserved; the lower-level registration APIs remain unchanged.Per-resource
HideAsNotFoundgives missing, removed (Gone), and withheld resources the same public NotFound, without original metadata or causes.HideExistence<TResource>(code: ..., detail: ...)optionally supplies fixed public metadata; the projection form selects a separate public type.Domain event dispatch: implement
IDomainEventHandler<TEvent>, register withAddDomainEventDispatch(...), and the framework snapshotsIAggregate.UncommittedEvents()after a successfulResult<TAggregate>command. It publishes only that snapshot, callsAcceptChanges()only on clean validation, and throwsDomainEventHandlerCascadedExceptionif the pending-event list at the end of dispatch differs from the entry snapshot (length or reference equality — i.e., a handler raised new events, cleared viaAcceptChanges, replaced, or reordered).Tracked-aggregate dispatch (opt-in):
TrackedAggregateDomainEventDispatchBehavior<,>reads committed aggregates from the unit of work and applies the same snapshot contract across all of them, including cross-aggregate cascade detection. Mutually exclusive with response-shape dispatch.Operational caveat: dispatch runs after EF unit-of-work commit. Cascade detection can return a failure-shaped response after the database write is durable. In-pipeline handler exceptions are logged and swallowed by the default publisher, because this path is post-commit and cannot retry; durable at-least-once side effects require the shipped transactional outbox (
Trellis.EntityFrameworkCore.Outbox), which retries failed handlers individually.Nested domain-event dispatch waits for the owning successful unit-of-work commit, retaining inner aggregate responses even when the outer command returns a DTO or Unit. Failure/throw discards the dispatch batch without clearing events; the outbox still captures events on successful
FailAfterCommitsaves.IIntegrationEventCollectoris translator-only. The outbox relay opensBeginTranslation()while publishing and draining;Addfrom a command or outside that active lease throws rather than silently losing events.IntegrationMessageContext.BeginCorrelation("workflow-id")supplies application-owned business correlation; inbox dispatch scopes inherit nonblank inbound correlation and make the inbound message id available to outbox capture.OutboundIntegrationMessagecarries the persisted lineage and W3C trace context across transports.
Documentation
- Handler migration and dispatch contracts: standard managed registrations supply the context automatically; manual authorization pipelines must add it before authorization.
- Native AOT registration: literal generator
typeof(...)configuration provides closed behaviors. Native DI cannot close open behaviors over structResult<T>responses; do not mix that shape withAddTrellisBehaviorsor builder slots that imply it. - Full documentation
- Package API reference
Part of Trellis
This package is part of the Trellis framework.
| 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
- Mediator.Abstractions (>= 3.0.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Options (>= 10.0.12)
- OpenTelemetry.Api (>= 1.19.1)
- Trellis.Authorization (>= 3.0.0-alpha.554)
- Trellis.Core (>= 3.0.0-alpha.554)
- Trellis.Persistence.Abstractions (>= 3.0.0-alpha.554)
NuGet packages (7)
Showing the top 5 NuGet packages that depend on Trellis.Mediator:
| Package | Downloads |
|---|---|
|
Trellis.EntityFrameworkCore
EF Core integration for Trellis. Convention-based value converter registration, Result-returning persistence, Maybe/Result query extensions, typed seek pagination, and translated spherical nearby-query expressions. |
|
|
Trellis.Mediator.FluentValidation
Mediator pipeline adapter that plugs FluentValidation validators into the Trellis Mediator validation stage. Open-generic IMessageValidator<TMessage> that resolves every IValidator<TMessage> registered in DI and aggregates failures into a single Error.InvalidInput response. |
|
|
Trellis.ServiceDefaults
Opinionated service composition defaults for Trellis web services. Provides a tiered builder that wires ASP integration, Mediator behaviors, FluentValidation, resource authorization, actor providers, and EF Core Unit of Work in canonical order. |
|
|
Trellis.Testing.Worker
Integration-test harness for BackgroundService workers built on Trellis - prewired IHost, FakeTimeProvider, TestActorProvider, domain-event capture, and tick-completion primitives |
|
|
Trellis.EntityFrameworkCore.Outbox
Transactional outbox for Trellis. Atomically captures aggregate domain events to an EF Core table in the same transaction as the aggregate change, then relays them to Trellis domain-event handlers — durable, at-least-once, in-process dispatch. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.0-alpha.557 | 105 | 10/8/2026 |
| 3.0.0-alpha.554 | 98 | 10/8/2026 |
| 3.0.0-alpha.553 | 64 | 10/7/2026 |
| 3.0.0-alpha.542 | 133 | 10/5/2026 |
| 3.0.0-alpha.539 | 90 | 10/4/2026 |
| 3.0.0-alpha.532 | 142 | 10/2/2026 |
| 3.0.0-alpha.527 | 108 | 10/1/2026 |
| 3.0.0-alpha.526 | 82 | 9/30/2026 |
| 3.0.0-alpha.524 | 86 | 9/27/2026 |
| 3.0.0-alpha.520 | 106 | 9/25/2026 |
| 3.0.0-alpha.516 | 233 | 9/22/2026 |
| 3.0.0-alpha.513 | 90 | 9/22/2026 |
| 3.0.0-alpha.505 | 216 | 9/13/2026 |
| 3.0.0-alpha.495 | 275 | 8/24/2026 |
| 3.0.0-alpha.458 | 267 | 8/19/2026 |
| 3.0.0-alpha.455 | 178 | 8/19/2026 |
| 3.0.0-alpha.449 | 127 | 8/18/2026 |
| 3.0.0-alpha.447 | 125 | 8/18/2026 |
| 3.0.0-alpha.432 | 169 | 7/6/2026 |
| 3.0.0-alpha.428 | 149 | 7/3/2026 |