Requests a service of type type, by its key, in the run of a step or a rescue step: the workflow's provider of that key lends one for the attempt. A service is always required.
type
run
import assert from "node:assert/strict";import { service, serviceType, type ServiceType } from "itinera/service";import { type Outcome, Step, step } from "itinera/step";interface PaymentGateway { take(amount: number): string;}const PAYMENT_GATEWAY: ServiceType<PaymentGateway> = serviceType<PaymentGateway>("PaymentGateway");@step()class Charge extends Step { override run( @service("payments", PAYMENT_GATEWAY) payments: PaymentGateway, ): Outcome { payments.take(40); return this.succeed(); }}const taken: number[] = [];const gateway: PaymentGateway = { take: (amount) => { taken.push(amount); return `${String(amount)} paid`; },};new Charge().run(gateway);assert.equal(PAYMENT_GATEWAY.name, "PaymentGateway");assert.deepEqual(taken, [40]); Copy
import assert from "node:assert/strict";import { service, serviceType, type ServiceType } from "itinera/service";import { type Outcome, Step, step } from "itinera/step";interface PaymentGateway { take(amount: number): string;}const PAYMENT_GATEWAY: ServiceType<PaymentGateway> = serviceType<PaymentGateway>("PaymentGateway");@step()class Charge extends Step { override run( @service("payments", PAYMENT_GATEWAY) payments: PaymentGateway, ): Outcome { payments.take(40); return this.succeed(); }}const taken: number[] = [];const gateway: PaymentGateway = { take: (amount) => { taken.push(amount); return `${String(amount)} paid`; },};new Charge().run(gateway);assert.equal(PAYMENT_GATEWAY.name, "PaymentGateway");assert.deepEqual(taken, [40]);
Requests a service of type
type, by its key, in therunof a step or a rescue step: the workflow's provider of that key lends one for the attempt. A service is always required.