mscharley/dot

Optional injections don't check parent containers for values before returning empty values

Closed this issue · 0 comments

Describe the bug.

When retrieving an optional value, a child container will only check itself for a value, it won't check parent containers if it can't find any values.

Steps to reproduce

import { createContainer, Token } from "@mscharley/dot";

const child = new Token("childContainer");
const foo = new Token("foo");

const container = createContainer();
container
  .bind(child)
  .inSingletonScope()
  .toFactory(
    [],
    ({ container: ctr }) =>
      () =>
        ctr.createChild(),
  );
container.bind(foo).toConstantValue(10);

console.log("parent foo =", await container.get(foo, { optional: true }));
console.log("child foo =", await container.get(child).then((c) => c.get(foo, { optional: true })));

Expected behaviour

I would expect both logs to output the same value

DOT

1.4.11

TypeScript

5.2

Decorator type

Typescript Experimental

Node

18/20

Add any other context about the problem here.

No response