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 Task<Either<Exception, OrderResult>> Junctions() =>
        Chain<ValidateOrder>()              // Execute junction, auto-wiring input/output via Memory
        .Chain<ProcessPayment>()
        .Chain<SendConfirmation>().Resolve();     // Final result extracted from Memory automatically

Junctions() is the only way to declare a chain. There is no imperative alternative: a chain assembled in code has no single shape, so a host could not check it before serving traffic. Work that used to sit above the chain belongs in a junction at the head of it.

MethodDescription
JunctionsOverride to define the train's route, the primary way to compose junctions
ChainExecutes a junction, wiring its input from Memory and storing its output back
ShortCircuitExecutes a junction whose Right value becomes the train's result; later junctions still run
ExtractPulls a nested property/field out of a Memory object into its own Memory slot
AddServicesStores DI services into Memory so junctions can access them
ResolveEnds the chain, taking the TReturn result out of Memory
Run / RunEitherExecutes the train from the outside. Run throws on failure, RunEither returns Either
DecideAsks a decider several typed questions about a value in Memory, in one call, and stores the typed decisions
SwitchSends the train down one of several declared tracks, chosen by a decision
GateRoutes on the probability that a yes/no answer is yes
ScaleRoutes on where the state falls on an ordered scale
DeclaredChainReads the declared chain without running it, and verifies it with ChainVerification.Verify