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 automaticallyJunctions() 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.
| 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 whose Right value becomes the train's result; later junctions still run |
| 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 |
| Resolve | Ends the chain, taking the TReturn result out of Memory |
| Run / RunEither | Executes the train from the outside. Run throws on failure, RunEither returns Either |
| Decide | Asks a decider several typed questions about a value in Memory, in one call, and stores the typed decisions |
| Switch | Sends the train down one of several declared tracks, chosen by a decision |
| Gate | Routes on the probability that a yes/no answer is yes |
| Scale | Routes on where the state falls on an ordered scale |
| DeclaredChain | Reads the declared chain without running it, and verifies it with ChainVerification.Verify |