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 dba6480..841be84 100644 --- a/src/ts/@overflow/commons/application/context/instance_definition_reader.ts +++ b/src/ts/@overflow/commons/application/context/instance_definition_reader.ts @@ -2,23 +2,30 @@ import { ClassType, } from '@overflow/commons/core/type'; +import { Assert } from '@overflow/commons/core/util'; + import { InstanceDefinitionRegistry, InstanceNameGenerator, + InstanceDefinition, } from '@overflow/commons/di/factory'; + export class InstanceDefinitionReader { private instanceDefinitionRegistry: InstanceDefinitionRegistry; private instanceNameGenerator: InstanceNameGenerator; public constructor(registry: InstanceDefinitionRegistry) { - // + Assert.notNull(registry, 'InstanceDefinitionRegistry must not be null'); + this.instanceDefinitionRegistry = registry; } public register(...injectables: ClassType[]): void { - // + injectables.forEach(injectable => { + this.registerInstance(injectable); + }); } public registerInstance(injectable: ClassType): void { - // + let instanceDefinition: InstanceDefinition = new InstanceDefinition(injectable); } } diff --git a/src/ts/@overflow/commons/application/context/scope_metadata_resolver.ts b/src/ts/@overflow/commons/application/context/scope_metadata_resolver.ts new file mode 100644 index 0000000..6be8ab2 --- /dev/null +++ b/src/ts/@overflow/commons/application/context/scope_metadata_resolver.ts @@ -0,0 +1,21 @@ +import { + Annotation, +} from '@overflow/commons/core/reflect'; + +import { + ClassType, +} from '@overflow/commons/core/type'; + +import { ScopeAnnotation } from '@overflow/commons/di/decorators'; +import { InstanceDefinition } from '@overflow/commons/di/factory'; +import { ScopeType } from '@overflow/commons/di/type'; + + +export class ScopeMetadataResolver { + protected static scopeAnnotationType: ClassType = ScopeAnnotation; + + public resolveScopeMetadata(definition: InstanceDefinition): ScopeType { + let scope: ScopeType = ScopeType.Default; + + } +} diff --git a/src/ts/@overflow/commons/di/decorators/index.ts b/src/ts/@overflow/commons/di/decorators/index.ts index 628fa95..9fb9d18 100644 --- a/src/ts/@overflow/commons/di/decorators/index.ts +++ b/src/ts/@overflow/commons/di/decorators/index.ts @@ -1,6 +1,9 @@ export * from './inject'; export * from './injectable'; +export * from './named'; export * from './post_construct'; export * from './pre_destroy'; +export * from './qualifier'; export * from './resource'; +export * from './scope'; export * from './value'; diff --git a/src/ts/@overflow/commons/di/decorators/scope.ts b/src/ts/@overflow/commons/di/decorators/scope.ts index e69de29..a87ddd1 100644 --- a/src/ts/@overflow/commons/di/decorators/scope.ts +++ b/src/ts/@overflow/commons/di/decorators/scope.ts @@ -0,0 +1,46 @@ +import { + Annotation, + Decorator, +} from '@overflow/commons/core/reflect'; + +import { + PropertyKeyType, + TypeUtil, +} from '@overflow/commons/core/type'; + +import { + InstanceNameType, + ScopeType, +} from '@overflow/commons/di/type'; + +export interface ScopeAnnotationAttributes { + value?: ScopeType; +} + +export class ScopeAnnotation extends Annotation { + public readonly attributes: ScopeAnnotationAttributes = { + value: ScopeType.Default, + }; + + public constructor(value: ScopeType | ScopeAnnotationAttributes) { + super(); + + if (undefined !== (value).value) { + this.copyAttributes(this.attributes, value); + } else { + this.attributes.value = value; + } + } + + public classDecorator(target: TFunction): TFunction | void { + console.log('Scope'); + } + + public methodDecorator(target: Object, propertyKey: PropertyKeyType, + descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor | void { + console.log('Scope'); + } + +} + +export const Scope = Decorator.create(ScopeAnnotation); diff --git a/src/ts/@overflow/commons/di/factory/instance_definition.ts b/src/ts/@overflow/commons/di/factory/instance_definition.ts index 512c5f1..16c8abb 100644 --- a/src/ts/@overflow/commons/di/factory/instance_definition.ts +++ b/src/ts/@overflow/commons/di/factory/instance_definition.ts @@ -36,6 +36,11 @@ export class InstanceDefinition { return this.attributes.keys(); } + // Metadata + public getMetadata(): AnnotationMetadata { + return undefined; + } + public setScope(scope: ScopeType): void { this.scope = scope; } diff --git a/src/ts/@overflow/commons/di/factory/instance_name_generator.ts b/src/ts/@overflow/commons/di/factory/instance_name_generator.ts index c4aca24..1a2632a 100644 --- a/src/ts/@overflow/commons/di/factory/instance_name_generator.ts +++ b/src/ts/@overflow/commons/di/factory/instance_name_generator.ts @@ -5,4 +5,9 @@ export class InstanceNameGenerator { public generateInstanceName(definition: InstanceDefinition, registry: InstanceDefinitionRegistry): string { return undefined; } + + protected determineInstanceNameFromAnnotation(definition: InstanceDefinition): string { + return undefined; + } } + diff --git a/src/ts/@overflow/commons/di/type/annotation_metadata.ts b/src/ts/@overflow/commons/di/type/annotation_metadata.ts new file mode 100644 index 0000000..0ffbd4f --- /dev/null +++ b/src/ts/@overflow/commons/di/type/annotation_metadata.ts @@ -0,0 +1,3 @@ +export class AnnotationMetadata { + +}