Trellis.Mediator
3.0.0-alpha.520
See the version list below for details.
dotnet add package Trellis.Mediator --version 3.0.0-alpha.520
NuGet\Install-Package Trellis.Mediator -Version 3.0.0-alpha.520
<PackageReference Include="Trellis.Mediator" Version="3.0.0-alpha.520" />
<PackageVersion Include="Trellis.Mediator" Version="3.0.0-alpha.520" />
<PackageReference Include="Trellis.Mediator" />
paket add Trellis.Mediator --version 3.0.0-alpha.520
#r "nuget: Trellis.Mediator, 3.0.0-alpha.520"
#:package Trellis.Mediator@3.0.0-alpha.520
#addin nuget:?package=Trellis.Mediator&version=3.0.0-alpha.520&prerelease
#tool nuget:?package=Trellis.Mediator&version=3.0.0-alpha.520&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
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
AuthFailureExposurePolicy(HideAsNotFound) translatesForbidden/AuthenticationRequiredtoNotFound(ResourceRef)for sensitive resources whose mere existence is itself a leak; configured viaResourceAuthorizationOptions.HideExistence<TResource>().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
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.18.0)
- Trellis.Authorization (>= 3.0.0-alpha.520)
- Trellis.Core (>= 3.0.0-alpha.520)
- Trellis.Persistence.Abstractions (>= 3.0.0-alpha.520)
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 for Trellis primitives, Result-returning SaveChanges wrappers, Maybe/Result query extensions, and provider-agnostic database exception classification. |
|
|
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.524 | 53 | 9/27/2026 |
| 3.0.0-alpha.520 | 85 | 9/25/2026 |
| 3.0.0-alpha.516 | 177 | 9/22/2026 |
| 3.0.0-alpha.513 | 77 | 9/22/2026 |
| 3.0.0-alpha.505 | 211 | 9/13/2026 |
| 3.0.0-alpha.495 | 272 | 8/24/2026 |
| 3.0.0-alpha.458 | 257 | 8/19/2026 |
| 3.0.0-alpha.455 | 166 | 8/19/2026 |
| 3.0.0-alpha.449 | 122 | 8/18/2026 |
| 3.0.0-alpha.447 | 121 | 8/18/2026 |
| 3.0.0-alpha.432 | 167 | 7/6/2026 |
| 3.0.0-alpha.428 | 146 | 7/3/2026 |
| 3.0.0-alpha.425 | 176 | 6/27/2026 |
| 3.0.0-alpha.419 | 114 | 6/24/2026 |
| 3.0.0-alpha.418 | 269 | 6/23/2026 |
| 3.0.0-alpha.417 | 110 | 6/23/2026 |
| 3.0.0-alpha.397 | 147 | 6/18/2026 |
| 3.0.0-alpha.396 | 93 | 6/18/2026 |
| 3.0.0-alpha.394 | 114 | 6/18/2026 |
| 3.0.0-alpha.385 | 99 | 6/15/2026 |