Train Methods
Methods available on Train<TInput, TReturn> for composing junctions. These are the core building blocks of every Trax train pipeline.
A typical train overrides Junctions() and calls chain methods directly:
protected override OrderResult Junctions() =>
Chain<ValidateOrder>() // Execute junction, auto-wiring input/output via Memory
.Chain<ProcessPayment>()
.Chain<SendConfirmation>(); // Final result extracted from Memory automatically
For advanced cases (custom logic, async setup, manual Either construction), override RunInternal instead:
protected override async Task<Either<Exception, OrderResult>> RunInternal(OrderInput input) =>
Activate(input)
.Chain<ValidateOrder>()
.Chain<ProcessPayment>()
.Chain<SendConfirmation>()
.Resolve();
| Method | Description |
|---|---|
| Junctions | Override to define the train’s route, the primary way to compose junctions |
| Chain | Executes a junction, wiring its input from Memory and storing its output back |
| ShortCircuit | Executes a junction that can return early, bypassing remaining junctions |
| Extract | Pulls a nested property/field out of a Memory object into its own Memory slot |
| AddServices | Stores DI services into Memory so junctions can access them |
| Activate | Stores the train input into Memory (used in RunInternal path) |
| Resolve | Extracts the final TReturn result from Memory (used in RunInternal path) |
| Run / RunEither | Executes the train from the outside. Run throws on failure, RunEither returns Either |