Browse Source

fixes and tested deployment

master
nitowa 2 years ago
parent
commit
076064ad98
5 changed files with 8 additions and 4 deletions
  1. 3
    0
      Index.ts
  2. 0
    0
      index.ts
  3. 1
    0
      package.json
  4. 2
    2
      src/Decorator.ts
  5. 2
    2
      src/Injector.ts

+ 3
- 0
Index.ts View File

@@ -0,0 +1,3 @@
1
+export * from './src/Decorator';
2
+export * from './src/Injector';
3
+export * from './src/Types';

+ 0
- 0
index.ts View File


+ 1
- 0
package.json View File

@@ -28,6 +28,7 @@
28 28
     "reflect-metadata": "^0.1.13"
29 29
   },
30 30
   "devDependencies": {
31
+    "typescript": "^4.7.2",
31 32
     "@types/node": "^11.13.19",
32 33
     "@types/chai": "^4.2.21",
33 34
     "@types/expect": "^1.20.4",

+ 2
- 2
src/Decorator.ts View File

@@ -15,7 +15,7 @@ export function Singleton(_interface?: Constructor<any>): GenericClassDecorator<
15 15
 }
16 16
 
17 17
 export function Inject(clazz: Constructor<any>) {
18
-  return function (prototype: Object, key: string) {
19
-    Injector['injectionQueue'].push({ injectionType: clazz, prototype: prototype, injectIntoKey: key })
18
+  return function (instance: Object, key: string) {
19
+    Injector['injectionQueue'].push({ injectionType: clazz, instance: instance, injectIntoKey: key })
20 20
   }
21 21
 }

+ 2
- 2
src/Injector.ts View File

@@ -13,7 +13,7 @@ class _Injector {
13 13
    * @param {Type<any>} target
14 14
    * @returns {T}
15 15
    */
16
-  public resolve<T>(target: Type<T>): T {
16
+  public resolve<T>(target: Constructor<T>): T {
17 17
     if (!this.initialized) {
18 18
       this.initialize()
19 19
       this.initialized = true
@@ -55,7 +55,7 @@ class _Injector {
55 55
       const inj = this.injectionQueue.shift()
56 56
 
57 57
       if (this.moduleObjs[inj.injectionType.name]) {
58
-        inj.prototype[inj.injectIntoKey] = this.moduleObjs[inj.injectionType.name]
58
+        this.moduleObjs[inj.instance.constructor.name][inj.injectIntoKey] = this.moduleObjs[inj.injectionType.name]
59 59
       } else {
60 60
         throw new Error("Cannot resolve injection token " + inj.injectionType.name)
61 61
       }

Loading…
Cancel
Save