Skip to content

Commit

Permalink
fix: async service instantiating
Browse files Browse the repository at this point in the history
  • Loading branch information
matuszeman committed Jun 16, 2017
1 parent 64a44c7 commit e5621d5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bb-dic",
"version": "1.0.1",
"version": "1.0.2",
"description": "A dependency injection container",
"main": "src/index.js",
"scripts": {
Expand Down
5 changes: 3 additions & 2 deletions src/dic.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,9 @@ class Dic {

const ret = [];
for (const param of params) {
if (def.inject[param]) {
return def.inject[param];
if (def.inject && def.inject[param]) {
ret.push(def.inject[param]);
continue;
}
ret.push(await container.getAsync(param, opts));
}
Expand Down
18 changes: 18 additions & 0 deletions src/dic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,22 @@ describe('Dic', () => {
expect(one).equal(two.one);
});
});

describe('.createInstanceAsync()', () => {
beforeEach(function() {
this.dic.class('one', OneConcrete);
});

it('inject works', async function() {
const {dic} = this;
const dummy = {dummy: 'object'};
const ins = await dic.createInstanceAsync({
class: Two,
inject: {
one: dummy
}
});
expect(ins.one).equal(dummy);
});
});
});

0 comments on commit e5621d5

Please sign in to comment.