Skip to content

Commit

Permalink
Fixes #442 (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
remojansen committed Dec 10, 2016
1 parent 0605daf commit ee8562e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/planning/planner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function _getActiveBindings(
let activeBindings: interfaces.Binding<any>[] = [];

// 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) => {
Expand Down
30 changes: 30 additions & 0 deletions test/bugs/bugs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Weapon>(TYPES.Weapon).to(Katana).whenTargetNamed("sword");

let throws = () => { container.getNamed<Weapon>(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);

});

});

0 comments on commit ee8562e

Please sign in to comment.