Skip to content

Commit

Permalink
fix: fix dep map generator err in constructor inject
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 committed Nov 13, 2018
1 parent d94d5e9 commit 9d7abe6
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ GuangWong <guangwong@gmail.com>
Harry Chen <czy88840616@gmail.com>
Lellansin <Lellansin@gmail.com>
ZQun <13304061222@qq.com>
dev2geek <dev2geek@gmail.com>
dodoT2 <q_un@foxmail.com>
kurten <chinkurten@gmail.com>
冰森 <lellansin@gmail.com>
2 changes: 2 additions & 0 deletions packages/context/src/factory/applicationContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ export class BaseApplicationContext extends EventEmitter implements IApplication
let constructorArgs = definition.constructorArgs || [];
constructorArgs = constructorArgs.map((ref) => {
return ref.name;
}).filter(name => {
return !!name;
});

const properties = (definition.properties && definition.properties.keys().map((key) => {
Expand Down
31 changes: 29 additions & 2 deletions packages/context/test/fixtures/complex_injection/dbAPI.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
import { ScopeEnum, scope, provide } from '../../../src';
import { inject, provide, scope, ScopeEnum } from '../../../src';

@provide()
export class A {
config = {
c: 1
};
}

@provide()
export class B {
config = {
c: 2
};
}

@scope(ScopeEnum.Singleton)
@provide('newKey')
export class DbAPI {
export class DbAPI {

private config;

constructor(
@inject() a,
hello,
@inject() b,
) {
this.config = a.config.c + b.config.c;
}

output() {
console.log(this.config);
}
}
15 changes: 14 additions & 1 deletion packages/context/test/unit/container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { childAsyncFunction, childFunction, testInjectAsyncFunction, testInjectF
import { DieselCar, DieselEngine, engineFactory, PetrolEngine } from '../fixtures/mix_sample';
import { UserService } from '../fixtures/complex_injection/userService';
import { UserController } from '../fixtures/complex_injection/userController';
import { DbAPI } from '../fixtures/complex_injection/dbAPI';
import { A, B, DbAPI } from '../fixtures/complex_injection/dbAPI';

const path = require('path');

Expand Down Expand Up @@ -176,5 +176,18 @@ describe('/test/unit/container.test.ts', () => {
expect(/newKey\(DbAPI\)/.test(newTree)).to.be.true;
});

it('should skip empty properties', async () => {
const applicationContext = new Container();
applicationContext.bind(UserService);
applicationContext.bind(UserController);
applicationContext.bind(DbAPI);
applicationContext.bind(A);
applicationContext.bind(B);
const newTree = await applicationContext.dumpDependency();
expect(/userController/.test(newTree)).to.be.true;
expect(/newKey\(DbAPI\)/.test(newTree)).to.be.true;
expect(/"newKey" -> "b"/.test(newTree)).to.be.true;
});

});
});
2 changes: 1 addition & 1 deletion packages/midway-core/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class MidwayLoader extends EggLoader {
private buildLoadDir(loadDir) {
const dirs = [];
for (let dir of loadDir) {
dirs.push(path.join(this.baseDir, dir));
dirs.push(path.join(this.appDir, dir));
}
return dirs;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/midway-web/config/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = (appInfo) => {
};

exports.container = {
loadDir: ['app', 'lib'],
loadDir: ['src'],
ignore: [
'**/node_modules/**',
'**/logs/**',
Expand Down

0 comments on commit 9d7abe6

Please sign in to comment.