Activate
Stores the train input (and optional extra objects) into Memory. Used in the RunInternal path as the first method call. After activation, the input is available to subsequent junctions via Memory’s type-based lookup.
Note: When using
Junctions(), activation happens automatically and you do not callActivateyourself. This method is only needed when overridingRunInternal.
Signature
// Train<TInput, TReturn>
public Monad<TInput, TReturn> Activate(TInput input, params object[] otherInputs)
// ServiceTrain<TIn, TOut>: overrides to inject ServiceProvider for junction DI
public new Monad<TIn, TOut> Activate(TIn input, params object[] otherInputs)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
input | TInput | Yes | The primary train input. Stored in Memory by its concrete type and all its interfaces. |
otherInputs | params object[] | No | Additional objects to store in Memory. Each is stored by its concrete type and interfaces. |
Returns
Monad<TInput, TReturn>, the train instance, for fluent chaining.
Examples
Basic Activation (RunInternal path)
protected override async Task<Either<Exception, OrderResult>> RunInternal(OrderInput input) =>
Activate(input)
.Chain<ValidateOrder>()
.Chain<ProcessPayment>()
.Resolve();
With Extra Inputs
Pass additional objects into Memory via the otherInputs parameter. This is only available in the RunInternal path, and it’s one of the reasons to use RunInternal over Junctions():
protected override async Task<Either<Exception, OrderResult>> RunInternal(OrderInput input) =>
Activate(input, _configService, _logger)
.Chain<ValidateOrder>()
.Resolve();
Behavior Details
Simple Types
The object is stored by its concrete type and all its interfaces. For example, if input is of type OrderInput which implements IOrderInput, it’s stored under both typeof(OrderInput) and typeof(IOrderInput).
Tuple Types
Each element of the tuple is extracted and stored individually. For example, (string, int) stores the string and int as separate Memory entries.
Null Input
If input is null, the train’s exception is set to "Input ({typeof(TInput)}) is null." and subsequent steps are short-circuited.
Remarks
- Memory is initialized with
Unit.Defaultundertypeof(Unit), allowing parameterless junction invocations. - The
otherInputsparameter follows the same tuple/interface storage rules as the primary input. - See Memory for details on how the type-keyed dictionary works.