Trellis.Mediator
3.0.0-alpha.432
dotnet add package Trellis.Mediator --version 3.0.0-alpha.432
NuGet\Install-Package Trellis.Mediator -Version 3.0.0-alpha.432
<PackageReference Include="Trellis.Mediator" Version="3.0.0-alpha.432" />
<PackageVersion Include="Trellis.Mediator" Version="3.0.0-alpha.432" />
<PackageReference Include="Trellis.Mediator" />
paket add Trellis.Mediator --version 3.0.0-alpha.432
#r "nuget: Trellis.Mediator, 3.0.0-alpha.432"
#:package Trellis.Mediator@3.0.0-alpha.432
#addin nuget:?package=Trellis.Mediator&version=3.0.0-alpha.432&prerelease
#tool nuget:?package=Trellis.Mediator&version=3.0.0-alpha.432&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)), "validation.error") { 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>. - 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.
- 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; durable at-least-once side effects require an outbox (planned, not shipped). Non-cancellation handler exceptions are still logged and swallowed by the default publisher.
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.9)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.9)
- Microsoft.Extensions.Options (>= 10.0.9)
- OpenTelemetry.Api (>= 1.16.0)
- Trellis.Authorization (>= 3.0.0-alpha.432)
- Trellis.Core (>= 3.0.0-alpha.432)
- Trellis.Persistence.Abstractions (>= 3.0.0-alpha.432)
NuGet packages (6)
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.432 | 103 | 7/6/2026 |
| 3.0.0-alpha.428 | 128 | 7/3/2026 |
| 3.0.0-alpha.425 | 159 | 6/27/2026 |
| 3.0.0-alpha.419 | 93 | 6/24/2026 |
| 3.0.0-alpha.418 | 252 | 6/23/2026 |
| 3.0.0-alpha.417 | 89 | 6/23/2026 |
| 3.0.0-alpha.397 | 128 | 6/18/2026 |
| 3.0.0-alpha.396 | 80 | 6/18/2026 |
| 3.0.0-alpha.394 | 100 | 6/18/2026 |
| 3.0.0-alpha.385 | 87 | 6/15/2026 |
| 3.0.0-alpha.382 | 88 | 6/12/2026 |
| 3.0.0-alpha.372 | 84 | 6/10/2026 |
| 3.0.0-alpha.360 | 119 | 6/7/2026 |
| 3.0.0-alpha.342 | 107 | 6/5/2026 |
| 3.0.0-alpha.337 | 81 | 6/3/2026 |
| 3.0.0-alpha.336 | 74 | 6/3/2026 |
| 3.0.0-alpha.304 | 82 | 5/29/2026 |
| 3.0.0-alpha.158 | 108 | 4/5/2026 |
| 3.0.0-alpha.157 | 79 | 4/4/2026 |
| 3.0.0-alpha.140 | 79 | 3/30/2026 |