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).
| Page | Description |
|---|---|
| TrainBus | ITrainBus interface: RunAsync, InitializeTrain |
| AddMediator | Registration and assembly scanning configuration |
| TrainDiscovery | ITrainDiscoveryService: discover registered trains and their input/output types |
| TrainExecution | ITrainExecutionService: queue or run trains programmatically with JSON input |
| Concurrency Limiting | Per-train and global concurrency limits for RUN executions |
| IEnqueueContextAccessor | The data context an enqueue commits on, for an OnQueue hook's side-effect. Defined in Trax.Effect.Data; AddMediator registers it |
| ITrustedExecutionScope | Marks an async flow as trusted infrastructure, which skips per-train authorization |
| ICurrentPrincipalProvider | Supplies the caller id the per-principal concurrency limit buckets by |
| IConcurrencyLimiter | The permit gate behind the concurrency limits |
| MediatorConfiguration | The resolved mediator settings, readable from the container |
| AddServiceTrainBus | The lower-level registration AddMediator performs, and RegisterServiceTrains |