diff --git a/Index.ts b/Index.ts new file mode 100644 index 0000000..944e780 --- /dev/null +++ b/Index.ts @@ -0,0 +1,3 @@ +export * from './src/Decorator'; +export * from './src/Injector'; +export * from './src/Types'; diff --git a/index.ts b/index.ts deleted file mode 100644 index e69de29..0000000 diff --git a/package.json b/package.json index c6a7e90..640a277 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "reflect-metadata": "^0.1.13" }, "devDependencies": { + "typescript": "^4.7.2", "@types/node": "^11.13.19", "@types/chai": "^4.2.21", "@types/expect": "^1.20.4", diff --git a/src/Decorator.ts b/src/Decorator.ts index a098ea0..8e65a01 100644 --- a/src/Decorator.ts +++ b/src/Decorator.ts @@ -15,7 +15,7 @@ export function Singleton(_interface?: Constructor): GenericClassDecorator< } export function Inject(clazz: Constructor) { - return function (prototype: Object, key: string) { - Injector['injectionQueue'].push({ injectionType: clazz, prototype: prototype, injectIntoKey: key }) + return function (instance: Object, key: string) { + Injector['injectionQueue'].push({ injectionType: clazz, instance: instance, injectIntoKey: key }) } } \ No newline at end of file diff --git a/src/Injector.ts b/src/Injector.ts index 90a3674..7a609d7 100644 --- a/src/Injector.ts +++ b/src/Injector.ts @@ -13,7 +13,7 @@ class _Injector { * @param {Type} target * @returns {T} */ - public resolve(target: Type): T { + public resolve(target: Constructor): T { if (!this.initialized) { this.initialize() this.initialized = true @@ -55,7 +55,7 @@ class _Injector { const inj = this.injectionQueue.shift() if (this.moduleObjs[inj.injectionType.name]) { - inj.prototype[inj.injectIntoKey] = this.moduleObjs[inj.injectionType.name] + this.moduleObjs[inj.instance.constructor.name][inj.injectIntoKey] = this.moduleObjs[inj.injectionType.name] } else { throw new Error("Cannot resolve injection token " + inj.injectionType.name) }