If i have only one named binding - no error if getNamed is called with invalid name.
Error No matching bindings found for serviceIdentifier: Symbol(IControlFlowReplacer) - named: XXX
In 3.0.0-rc1 returns BinaryExpressionControlFlowReplacer with named binding YYY
export const nodeControlFlowTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
bind<IControlFlowReplacer>(ServiceIdentifiers.IControlFlowReplacer)
.to(BinaryExpressionControlFlowReplacer)
.whenTargetNamed('YYY');
bind<IControlFlowReplacer>(ServiceIdentifiers['Factory<IControlFlowReplacer>'])
.toFactory<IControlFlowReplacer>((context: interfaces.Context) => {
return () => {
return context.container.getNamed<IControlFlowReplacer>(
ServiceIdentifiers.IControlFlowReplacer,
'XXX'
); // returns BinaryExpressionControlFlowReplacer
});
});
Hi @sanex3339 I don't think that change is is going to be possible. If no bindings match the name no bindings will be returned.
You can try using container.isBoundNamed:
let id = "XXXXX";
let name ="YYYYY";
let val = container.isBoundNamed(id, name) ? container.getNamed(id, name) : container.get(id);
If no bindings match the name no bindings will be returned.
Looks like you didn't understand me, because my bad english.
The problem is when i have only one named binding 'YYY' with service idendtifier 'A', when i will try to get from container dependency with service identifier 'A' but with name 'XXX' (which is not exist in the container), i will get (only one available in the container) named dependency with name 'YYY', like it is default binding. For my side this is strange, an error should trow.
When i have two or more binding with names 'XXX' and 'YYY' with service identifier 'A', when i will try to get from container dependency with service identifier 'A' but with name 'ZZZ' (which is not exist in the container), i will get an error, as expected.
Sorry for that. I think I understand the problem now. I will test it and fix it during the weekend :+1:
Thank you!
Fixed by https://github.com/inversify/InversifyJS/pull/443 and released as 3.0.0-rc.2 :tada:
Thank you
Most helpful comment
Fixed by https://github.com/inversify/InversifyJS/pull/443 and released as
3.0.0-rc.2:tada: