Skip to content

Commit e690617

Browse files
Fix #11
1 parent 71dace7 commit e690617

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-ioc",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "A Lightweight annotation-based dependency injection container for typescript.",
55
"author": "Thiago da Rosa de Bustamante <[email protected]>",
66
"scripts": {
@@ -9,9 +9,6 @@
99
"clean": "rimraf dist",
1010
"lint": "tslint ./src/**/*.ts ./test/**/*.ts",
1111
"format": "tsfmt -r",
12-
"prepublish": "npm run build",
13-
"deploy": "npm version patch && npm publish",
14-
"postversion": "git push origin master",
1512
"pretest": "cross-env NODE_ENV=test npm build && npm run lint",
1613
"test": "npm run test:es5 && npm run test:es6",
1714
"test:es5": "cross-env NODE_ENV=test mocha",
@@ -41,7 +38,8 @@
4138
"instrument": true
4239
},
4340
"dependencies": {
44-
"reflect-metadata": "^0.1.10"
41+
"reflect-metadata": "^0.1.10",
42+
"require-glob": "^3.2.0"
4543
},
4644
"devDependencies": {
4745
"@types/chai": "^3.5.1",

src/container-config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
export class ContainerConfig {
4+
static addSource(patterns: string | Array<string>, baseDir?: string) {
5+
const requireGlob = require('require-glob');
6+
baseDir = baseDir || process.cwd();
7+
requireGlob.sync(patterns, {
8+
cwd: baseDir
9+
});
10+
}
11+
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const isBrowser = new Function('try {return this===window;}catch(e){ return false;}');
3+
const isBrowser = new Function('try {return this===window;}catch(e){return false;}');
44

55
let useES6 = false;
66
if (!isBrowser()) {

test/unit/test.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'mocha';
44
import * as chai from 'chai';
55
import "reflect-metadata";
66
import * as IoC from "../../src/typescript-ioc";
7+
import { ContainerConfig } from "../../src/container-config";
78

89
const expect = chai.expect;
910

@@ -174,8 +175,12 @@ describe("Inheritance on autowired types", () => {
174175

175176
it("should inject all fields from all types and call all constructors", () => {
176177
const instance: Teste2 = new Teste2();
178+
const instance2: Teste2 = new Teste2();
179+
instance2.abc = 234;
177180
expect(instance.property1).to.exist;
178181
expect(instance.property2).to.exist;
182+
expect(instance.abc).to.eq(123);
183+
expect(instance2.abc).to.eq(234);
179184
expect(constructorsCalled).to.include.members(['TesteAbstract', 'Teste1', 'Teste2']);
180185
});
181186

@@ -382,6 +387,8 @@ describe("The IoC Container Config.to()", () => {
382387
describe("The IoC Container", () => {
383388

384389
it("should find classes in different files", () => {
390+
ContainerConfig.addSource('data/*', 'test');
391+
385392
const Worker = require('../data/classes').Worker;
386393
const instance = new Worker();
387394
expect(instance).to.exist;

tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
"noUnusedParameters": false,
1717
"noUnusedLocals": true,
1818
"outDir": "dist",
19+
"removeComments": true,
1920
"sourceMap": true,
2021
"strictNullChecks": false,
2122
"target": "es5"
2223
},
2324
"include": [
24-
"src/typescript-ioc.ts"
25+
"src/typescript-ioc.ts",
26+
"src/container-config.ts"
2527
]
2628
}

0 commit comments

Comments
 (0)