Trellis.Mediator 3.0.0-alpha.520

This is a prerelease version of Trellis.Mediator.
There is a newer prerelease version of this package available.
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
                    
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="Trellis.Mediator" Version="3.0.0-alpha.520" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Trellis.Mediator" Version="3.0.0-alpha.520" />
                    
Directory.Packages.props
<PackageReference Include="Trellis.Mediator" />
                    
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 Trellis.Mediator --version 3.0.0-alpha.520
                    
#r "nuget: Trellis.Mediator, 3.0.0-alpha.520"
                    
#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 Trellis.Mediator@3.0.0-alpha.520
                    
#: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=Trellis.Mediator&version=3.0.0-alpha.520&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Trellis.Mediator&version=3.0.0-alpha.520&prerelease
                    
Install as a Cake Tool

Trellis.Mediator

NuGet Package

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 your TracerProviderBuilder; without it the handler span is silently never recorded.

  • Short-circuits failures before handlers do unnecessary work.

  • Unified ValidationBehavior composes IValidate + every IMessageValidator<TMessage> (e.g., the Trellis.FluentValidation adapter) 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. Register SharedResourceLoaderById<TResource,TId> separately. Existing per-message loaders are preserved; the lower-level registration APIs remain unchanged.

  • Per-resource AuthFailureExposurePolicy (HideAsNotFound) translates Forbidden / AuthenticationRequired to NotFound(ResourceRef) for sensitive resources whose mere existence is itself a leak; configured via ResourceAuthorizationOptions.HideExistence<TResource>().

  • Domain event dispatch: implement IDomainEventHandler<TEvent>, register with AddDomainEventDispatch(...), and the framework snapshots IAggregate.UncommittedEvents() after a successful Result<TAggregate> command. It publishes only that snapshot, calls AcceptChanges() only on clean validation, and throws DomainEventHandlerCascadedException if 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 via AcceptChanges, 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 FailAfterCommit saves.

  • IIntegrationEventCollector is translator-only. The outbox relay opens BeginTranslation() while publishing and draining; Add from 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. OutboundIntegrationMessage carries the persisted lineage and W3C trace context across transports.

Documentation

Part of Trellis

This package is part of the Trellis framework.

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

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
Loading failed