From ee8562ec8c0f05b536ae65fa10f233f54657e36d Mon Sep 17 00:00:00 2001 From: "Remo H. Jansen" Date: Sat, 10 Dec 2016 03:53:58 +0100 Subject: [PATCH] Fixes #442 (#443) --- package.json | 2 +- src/planning/planner.ts | 2 +- test/bugs/bugs.test.ts | 30 ++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d4b380764..15de70c65 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "inversify", - "version": "3.0.0-rc.1", + "version": "3.0.0-rc.2", "description": "A powerful and lightweight inversion of control container for JavaScript and Node.js apps powered by TypeScript.", "main": "lib/inversify.js", "jsnext:main": "es/inversify.js", diff --git a/src/planning/planner.ts b/src/planning/planner.ts index 6dedc1742..2dab24248 100644 --- a/src/planning/planner.ts +++ b/src/planning/planner.ts @@ -53,7 +53,7 @@ function _getActiveBindings( let activeBindings: interfaces.Binding[] = []; // multiple bindings available - if (bindings.length > 1 && avoidConstraints === false) { + if (avoidConstraints === false) { // apply constraints if available to reduce the number of active bindings activeBindings = bindings.filter((binding) => { diff --git a/test/bugs/bugs.test.ts b/test/bugs/bugs.test.ts index 0ab047ccc..a27e91692 100644 --- a/test/bugs/bugs.test.ts +++ b/test/bugs/bugs.test.ts @@ -493,4 +493,34 @@ describe("Bugs", () => { }); + it("Should not be able to get a named dependency if no named bindings are gesitered", () => { + + const TYPES = { + Weapon: "Weapon" + }; + + interface Weapon { + name: string; + } + + @injectable() + class Katana implements Weapon { + public name: string; + public constructor() { + this.name = "Katana"; + } + } + + let container = new Container(); + container.bind(TYPES.Weapon).to(Katana).whenTargetNamed("sword"); + + let throws = () => { container.getNamed(TYPES.Weapon, "bow"); }; + + let error = `No matching bindings found for serviceIdentifier: Weapon\n Weapon ` + + `- named: bow \n\nRegistered bindings:\n Katana - named: sword `; + + expect(throws).to.throw(error); + + }); + });