From 83858415f7004d2a63adbc64958a03070a2a7343 Mon Sep 17 00:00:00 2001 From: Byung Jun Park Date: Wed, 26 Jul 2017 00:39:03 +0900 Subject: [PATCH] ing --- .../commons/context/decorator/inject.ts | 18 ++++++++---------- src/ts/@overflow/commons/context/index.ts | 4 +++- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/ts/@overflow/commons/context/decorator/inject.ts b/src/ts/@overflow/commons/context/decorator/inject.ts index 814e35c..a86515a 100644 --- a/src/ts/@overflow/commons/context/decorator/inject.ts +++ b/src/ts/@overflow/commons/context/decorator/inject.ts @@ -11,19 +11,17 @@ const inject = (config?: Config) => { if (typeof parameterIndex === 'number') { // tagParameter(target, targetKey, index, metadata); } else { + let meta: Map; if (Reflect.hasOwnMetadata(METADATA.INJECT_TAG, target)) { - let meta = Reflect.getMetadata(METADATA.INJECT_TAG, target); + meta = Reflect.getMetadata(METADATA.INJECT_TAG, target); } else { - let meta: string[]; + meta = new Map(); + Reflect.defineMetadata(METADATA.INJECT_TAG, meta, target); } - - - let types = Reflect.getMetadata(METADATA.INJECT_TAG, target); - - // Reflect.defineMetadata(METADATA.PARAM_TYPES, types, target); - - console.log(types); - // tagProperty(target, targetKey, metadata); + if (meta.has(propertyKey)) { + throw new Error('Cannot apply @injectable decorator multiple times.'); + } + meta.set(propertyKey, config); } }; }; diff --git a/src/ts/@overflow/commons/context/index.ts b/src/ts/@overflow/commons/context/index.ts index 3fa639c..08c744f 100644 --- a/src/ts/@overflow/commons/context/index.ts +++ b/src/ts/@overflow/commons/context/index.ts @@ -18,7 +18,9 @@ class AppContext { } public static getService(clazz: {new(...args: any[]): T}): T { - let types = Reflect.getMetadata(METADATA.PARAM_TYPES, clazz); + let s = Object.getPrototypeOf(clazz.prototype); + let types1 = Reflect.getMetadata(METADATA.INJECT_TAG, s); + let types2 = Reflect.getMetadata(METADATA.INJECT_TAG, clazz); let i = new clazz();