mscharley/dot

Autobinding takes precedence over explicit bindings in parent containers

Closed this issue · 0 comments

Describe the bug.

If you have a child container which has autobinding enabled, and a parent container with an explicit binding for a class identifier then the child container will prioritise the autobinding feature over the explicit binding in the parent. This behaviour feels backwards. If a person has provided explicit instructions on how to bind something in the parent container then we should fetch the implementation from the parent container before falling back to autobinding.

Steps to reproduce

class Test {}

const c = createContainer();
c.bind(Test).toSelf();
const child = c.createChild({ autobindClasses: true });

await child.get(Test);

Expected behaviour

This fails because it doesn't have an @injectable() decorator instead of succeeding using the explicit binding in the parent container.

IOC-Deco

1.2.10

TypeScript

5.2.2

Decorator type

Typescript Experimental

Node

No response

Add any other context about the problem here.

No response