INNER CODE UNIT · TypeScript
createLinearChain
jeffijoe/awilix · benchmarks/helpers.ts:11
export function createLinearChain(
depth: number,
lifetime: string = Lifetime.TRANSIENT,
): AwilixContainer {
const container = createContainer()
const regs: Record<string, any> = {}
// leaf
regs['leaf'] = asFunction(() => 'value', { lifetime: lifetime as any })
// mid(depth-2) -> ... -> mid0 -> entry
for (let i = depth - 2; i >= 0; i--) {
const next = i === depth - 2 ? 'leaf' : `mid${i + 1}`
regs[`mid${i}`] = asFunction((cradle: any) => cradle[next], {
lifetime: lifetime as any,
})
}