Mediator API

The mediator pattern in Trax.Mediator routes train execution by input type. Instead of injecting specific train interfaces, you inject ITrainBus and dispatch by passing the input object. The bus discovers and runs the correct train automatically.

// Instead of:
var result = await _createOrderTrain.Run(orderInput);
 
// You can:
var result = await _trainBus.RunAsync<OrderResult>(orderInput);

This decouples callers from specific train implementations and enables train composition (a junction can dispatch another train; the child is recorded as a run of its own, not linked to the parent, see Nested Trains).

PageDescription
TrainBusITrainBus interface: RunAsync, InitializeTrain
AddMediatorRegistration and assembly scanning configuration
TrainDiscoveryITrainDiscoveryService: discover registered trains and their input/output types
TrainExecutionITrainExecutionService: queue or run trains programmatically with JSON input
Concurrency LimitingPer-train and global concurrency limits for RUN executions
IEnqueueContextAccessorThe data context an enqueue commits on, for an OnQueue hook's side-effect. Defined in Trax.Effect.Data; AddMediator registers it
ITrustedExecutionScopeMarks an async flow as trusted infrastructure, which skips per-train authorization
ICurrentPrincipalProviderSupplies the caller id the per-principal concurrency limit buckets by
IConcurrencyLimiterThe permit gate behind the concurrency limits
MediatorConfigurationThe resolved mediator settings, readable from the container
AddServiceTrainBusThe lower-level registration AddMediator performs, and RegisterServiceTrains