Trains and Junctions
The types you derive from and register: the train and junction base classes, the contracts they implement, the exception a failure carries, and the helpers that put them in the container. The methods you call inside Junctions() are under Train Methods.
public interface ICreateOrderTrain : IServiceTrain<CreateOrderInput, OrderResult>;
public class CreateOrderTrain : ServiceTrain<CreateOrderInput, OrderResult>, ICreateOrderTrain
{
protected override Task<Either<Exception, OrderResult>> Junctions() =>
Chain<ValidateOrder>().Chain<ChargePayment>().Chain<PersistOrder>().Resolve();
}
public class ChargePayment(IPaymentGateway gateway) : EffectJunction<ValidatedOrder, PaymentReceipt>
{
public override Task<PaymentReceipt> Run(ValidatedOrder order) =>
gateway.Charge(order.CustomerId, order.Total, CancellationToken);
}| Page | Package | Description |
|---|---|---|
| Train | Trax.Core | Train<TInput, TReturn>: the base class, with Run, RunEither, ExternalId and the chain methods |
| ServiceTrain | Trax.Effect | ServiceTrain<TIn, TOut> and IServiceTrain<TIn, TOut>: metadata, effects, lifecycle hooks, container-built junctions |
| Junction | Trax.Core | Junction<TIn, TOut> and IJunction<TIn, TOut>: one unit of work on the railway |
| EffectJunction | Trax.Effect | EffectJunction<TIn, TOut>: a junction the junction effects can observe |
| IRoute | Trax.Core | IRoute<TIn, TOut>: the one-method contract every train implements |
| MonadTask | Trax.Core | MonadTask<TInput, TReturn>: the awaitable link a chain step returns |
| TrainException | Trax.Core | TrainException, TrainExceptionData and FailureClass: how a failure is raised and recorded |
| Route and Junction Registration | Trax.Effect | AddScopedTraxRoute, AddTransientTraxRoute, AddSingletonTraxRoute and the *TraxJunction aliases |