diff --git a/package-lock.json b/package-lock.json --- a/package-lock.json +++ b/package-lock.json @@ -84,7 +84,7 @@ }, "duplexer": { "version": "0.1.1", - "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz", + "resolved": "http://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz", "integrity": "sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=", "dev": true }, @@ -129,7 +129,7 @@ "dependencies": { "tape": { "version": "2.3.3", - "resolved": "https://registry.npmjs.org/tape/-/tape-2.3.3.tgz", + "resolved": "http://registry.npmjs.org/tape/-/tape-2.3.3.tgz", "integrity": "sha1-Lnzgox3wn41oUWZKcYQuDKUFevc=", "dev": true, "requires": { @@ -289,7 +289,7 @@ }, "path-is-absolute": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "resolved": "http://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, @@ -301,7 +301,7 @@ }, "readable-stream": { "version": "1.1.14", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", "dev": true, "requires": { @@ -354,7 +354,7 @@ }, "string_decoder": { "version": "0.10.31", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", "dev": true }, @@ -411,13 +411,13 @@ }, "through": { "version": "2.3.8", - "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", + "resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz", "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", "dev": true }, "through2": { "version": "0.2.3", - "resolved": "https://registry.npmjs.org/through2/-/through2-0.2.3.tgz", + "resolved": "http://registry.npmjs.org/through2/-/through2-0.2.3.tgz", "integrity": "sha1-6zKE2k6jEbbMis42U3SKUqvyWj8=", "dev": true, "requires": { diff --git a/src/ts/di/Configuration.ts b/src/ts/di/Configuration.ts --- a/src/ts/di/Configuration.ts +++ b/src/ts/di/Configuration.ts @@ -140,7 +140,7 @@ export class Configuration { } async _loadModule(moduleName: string) { - trace.log("loadModule {0}", moduleName); + trace.debug("loadModule {0}", moduleName); const m = await new Promise(fulfill => { this._require([moduleName], fulfill); diff --git a/src/ts/di/ServiceDescriptor.ts b/src/ts/di/ServiceDescriptor.ts --- a/src/ts/di/ServiceDescriptor.ts +++ b/src/ts/di/ServiceDescriptor.ts @@ -229,7 +229,6 @@ export class ServiceDescriptor implement injectMethod(instance, m, context, spec[m]); }); } - return instance; } } diff --git a/src/ts/di/TypeServiceDescriptor.ts b/src/ts/di/TypeServiceDescriptor.ts --- a/src/ts/di/TypeServiceDescriptor.ts +++ b/src/ts/di/TypeServiceDescriptor.ts @@ -15,12 +15,18 @@ export class TypeServiceDescriptor exten const ctor = this._type = opts.type; - if (this._params && this._params.length) { - this._factory = (...args) => { - const t = Object.create(ctor.prototype); - const inst = ctor.apply(t, args); - return isPrimitive(inst) ? t : inst; - }; + if (this._params) { + if (this._params.length) { + this._factory = (...args) => { + const t = Object.create(ctor.prototype); + const inst = ctor.apply(t, args); + return isPrimitive(inst) ? t : inst; + }; + } else { + this._factory = arg => { + return new ctor(arg); + }; + } } else { this._factory = () => { return new ctor(); diff --git a/test/js/mock/config1.js b/test/js/mock/config1.js --- a/test/js/mock/config1.js +++ b/test/js/mock/config1.js @@ -10,6 +10,9 @@ define({ provider: { $dependency: "db" } + }, + foo: { + $type: "./Foo:Foo" } } }, diff --git a/test/ts/ContainerTests.ts b/test/ts/ContainerTests.ts --- a/test/ts/ContainerTests.ts +++ b/test/ts/ContainerTests.ts @@ -87,7 +87,8 @@ test("Load configuration from module", a t.assert(!isNull(f1), "foo should be not null"); - const b1 = container.resolve("bar"); + const b1 = container.resolve("bar") as Bar; - t.assert(!isNull(b1), "foo should be not null"); + t.assert(!isNull(b1), "bar should not be null"); + t.assert(!isNull(b1.foo), "bar.foo should not be null"); }); diff --git a/test/ts/mock/Bar.ts b/test/ts/mock/Bar.ts --- a/test/ts/mock/Bar.ts +++ b/test/ts/mock/Bar.ts @@ -1,3 +1,12 @@ +import { Foo } from "./Foo"; + export class Bar { name = "bar"; + + foo: Foo; + + constructor(_opts) { + if (_opts && _opts.foo) + this.foo = _opts.foo; + } }