diff --git a/src/ts/@overflow/commons/application/context/instance_definition_reader.ts b/src/ts/@overflow/commons/application/context/instance_definition_reader.ts index 3ca6992..57ef68f 100644 --- a/src/ts/@overflow/commons/application/context/instance_definition_reader.ts +++ b/src/ts/@overflow/commons/application/context/instance_definition_reader.ts @@ -9,6 +9,11 @@ import { AnnotationUtils, } from '@overflow/commons/core/util'; +import { + InjectableAnnotation, + QualifierAnnotation, +} from '@overflow/commons/di/decorators'; + import { InstanceDefinition, InstanceDefinitionRegistry, @@ -21,8 +26,6 @@ import { } from '@overflow/commons/di/type'; import { ScopeMetadataResolver } from './scope_metadata_resolver'; -import { InjectableAnnotation, QualifierAnnotation } from '@overflow/commons/di/decorators'; - export class InstanceDefinitionReader { private instanceDefinitionRegistry: InstanceDefinitionRegistry; @@ -40,9 +43,10 @@ export class InstanceDefinitionReader { }); } - public registerInjectable(injectable: ClassType, name: InstanceNameType | undefined, ...qualifiers: QualifierAnnotation[]): void { + public registerInjectable + (injectable: ClassType, name: InstanceNameType | undefined, ...qualifierTypes: ClassType[]): void { if (!AnnotationUtils.hasAnnotation(injectable, InjectableAnnotation)) { - throw new NotInjectableError(); + throw new NotInjectableError(`Class[${injectable.name}] does not contains @Injectable`); } let definition: InstanceDefinition = new InstanceDefinition(injectable); diff --git a/src/ts/@overflow/commons/core/reflect/accessible_object.ts b/src/ts/@overflow/commons/core/reflect/accessible_object.ts index e33125a..15124ce 100644 --- a/src/ts/@overflow/commons/core/reflect/accessible_object.ts +++ b/src/ts/@overflow/commons/core/reflect/accessible_object.ts @@ -31,6 +31,23 @@ export abstract class AccessibleObject implements AnnotatedElement { return this._annotations; } + public getOwnAnnotationsByType(annotationClass: ClassType) + : AnnotationType[] | undefined { + if (0 === this._annotations.size) { + return undefined; + } + let results: AnnotationType[] = []; + for (const classType of Array.from(this._annotations.keys())) { + if (classType === annotationClass) { + results.push(this._annotations.get(classType)); + } + } + if (0 === results.length) { + return undefined; + } + return results; + } + public getAnnotation(annotationClass: ClassType): AnnotationType | undefined { return this.getOwnAnnotation(annotationClass); } @@ -39,4 +56,8 @@ export abstract class AccessibleObject implements AnnotatedElement { return this.getOwnAnnotations(); } + public getAnnotationsByType(annotationClass: ClassType) + : AnnotationType[] | undefined { + return this.getOwnAnnotationsByType(annotationClass); + } } diff --git a/src/ts/@overflow/commons/core/reflect/annotated_element.ts b/src/ts/@overflow/commons/core/reflect/annotated_element.ts index 1c3cbd5..b11636d 100644 --- a/src/ts/@overflow/commons/core/reflect/annotated_element.ts +++ b/src/ts/@overflow/commons/core/reflect/annotated_element.ts @@ -10,6 +10,8 @@ export interface AnnotatedElement { isAnnotationPresent(annotationClass: ClassType): boolean; getOwnAnnotation(annotationClass: ClassType): AnnotationType | undefined; getOwnAnnotations(): Map; + getOwnAnnotationsByType(annotationClass: ClassType): AnnotationType[] | undefined; getAnnotation(annotationClass: ClassType): AnnotationType | undefined; getAnnotations(): Map; + getAnnotationsByType(annotationClass: ClassType): AnnotationType[] | undefined; } diff --git a/src/ts/@overflow/commons/core/reflect/class.ts b/src/ts/@overflow/commons/core/reflect/class.ts index eea8ed5..946edbe 100644 --- a/src/ts/@overflow/commons/core/reflect/class.ts +++ b/src/ts/@overflow/commons/core/reflect/class.ts @@ -201,6 +201,23 @@ export class Class extends AccessibleObject { return annotations; } + public getAnnotationsByType(annotationClass: ClassType) + : AnnotationType[] | undefined { + let annotations = this.getAnnotations(); + if (0 === annotations.size) { + return undefined; + } + let results: AnnotationType[] = []; + for (const classType of Array.from(annotations.keys())) { + if (classType === annotationClass) { + results.push(annotations.get(classType)); + } + } + if (0 === results.length) { + return undefined; + } + return results; + } public getName(): string { return this._clazzType.name; diff --git a/src/ts/@overflow/commons/core/util/annotation.ts b/src/ts/@overflow/commons/core/util/annotation.ts index 1d04bbe..b21ffa2 100644 --- a/src/ts/@overflow/commons/core/util/annotation.ts +++ b/src/ts/@overflow/commons/core/util/annotation.ts @@ -33,4 +33,7 @@ export abstract class AnnotationUtils { return undefined; } + + + }