Recursive @multiInject in InversifyJS

22 views Asked by At

How can I inject multiple injections of type from container hierarchy?

Something like this:

const container = new Container();
const childContainer = container.createChild();

container.bind("MultiDep").toConstantValue(1);
childContainer.bind("MultiDep").toConstantValue(2);

@injectable()
class Consumer {
    constructor(@recursiveMultiInject("MultiDep") public deps: number[]) {
    }
}

container.bind(Consumer).toSelf();

console.log(container.get(Consumer).deps.length); // Should log 1
console.log(childContainer.get(Consumer).deps.length); // Should log 2

0

There are 0 answers