Let's imagine the following class hierarchy:
interface Weapon {
}
interface BladedWeapon extends Weapon {
}
class Katana implements BladedWeapon {
}
class Stick implements Weapon {
}
Current bindings are following:
container.bind<Weapon>('Weapon').to(Stick).whenTargetNamed('stick');
container.bind<Weapon>('Weapon').to(Katana).whenTargetNamed('katana');
In one part of my code I would like to get all instaces of Weapon
interface:
@multiInject('Weapon') weapons: Weapon[];
In the other part I would like to get katana:
@inject('Weapon') @named('katana') katana: Katana;
The problem is InversifyJS cannot perform multi-injection due to named bindings:
Error: No matching bindings found for serviceIdentifier: 'Weapon'
How to solve this issue?
P.S. I use InversifyJS 6.0.1