This commit is contained in:
crusader 2018-01-02 22:32:34 +09:00
parent 81fe770489
commit 606d7b0e82
7 changed files with 93 additions and 3 deletions

View File

@ -2,23 +2,30 @@ import {
ClassType, ClassType,
} from '@overflow/commons/core/type'; } from '@overflow/commons/core/type';
import { Assert } from '@overflow/commons/core/util';
import { import {
InstanceDefinitionRegistry, InstanceNameGenerator, InstanceDefinitionRegistry, InstanceNameGenerator,
InstanceDefinition,
} from '@overflow/commons/di/factory'; } from '@overflow/commons/di/factory';
export class InstanceDefinitionReader { export class InstanceDefinitionReader {
private instanceDefinitionRegistry: InstanceDefinitionRegistry; private instanceDefinitionRegistry: InstanceDefinitionRegistry;
private instanceNameGenerator: InstanceNameGenerator; private instanceNameGenerator: InstanceNameGenerator;
public constructor(registry: InstanceDefinitionRegistry) { public constructor(registry: InstanceDefinitionRegistry) {
// Assert.notNull(registry, 'InstanceDefinitionRegistry must not be null');
this.instanceDefinitionRegistry = registry;
} }
public register(...injectables: ClassType[]): void { public register(...injectables: ClassType[]): void {
// injectables.forEach(injectable => {
this.registerInstance(injectable);
});
} }
public registerInstance(injectable: ClassType): void { public registerInstance(injectable: ClassType): void {
// let instanceDefinition: InstanceDefinition = new InstanceDefinition(injectable);
} }
} }

View File

@ -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<Annotation> = ScopeAnnotation;
public resolveScopeMetadata(definition: InstanceDefinition): ScopeType {
let scope: ScopeType = ScopeType.Default;
}
}

View File

@ -1,6 +1,9 @@
export * from './inject'; export * from './inject';
export * from './injectable'; export * from './injectable';
export * from './named';
export * from './post_construct'; export * from './post_construct';
export * from './pre_destroy'; export * from './pre_destroy';
export * from './qualifier';
export * from './resource'; export * from './resource';
export * from './scope';
export * from './value'; export * from './value';

View File

@ -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 !== (<ScopeAnnotationAttributes>value).value) {
this.copyAttributes(this.attributes, <ScopeAnnotationAttributes>value);
} else {
this.attributes.value = value;
}
}
public classDecorator<TFunction extends Function>(target: TFunction): TFunction | void {
console.log('Scope');
}
public methodDecorator<T>(target: Object, propertyKey: PropertyKeyType,
descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void {
console.log('Scope');
}
}
export const Scope = Decorator.create(ScopeAnnotation);

View File

@ -36,6 +36,11 @@ export class InstanceDefinition {
return this.attributes.keys(); return this.attributes.keys();
} }
// Metadata
public getMetadata(): AnnotationMetadata {
return undefined;
}
public setScope(scope: ScopeType): void { public setScope(scope: ScopeType): void {
this.scope = scope; this.scope = scope;
} }

View File

@ -5,4 +5,9 @@ export class InstanceNameGenerator {
public generateInstanceName(definition: InstanceDefinition, registry: InstanceDefinitionRegistry): string { public generateInstanceName(definition: InstanceDefinition, registry: InstanceDefinitionRegistry): string {
return undefined; return undefined;
} }
protected determineInstanceNameFromAnnotation(definition: InstanceDefinition): string {
return undefined;
}
} }

View File

@ -0,0 +1,3 @@
export class AnnotationMetadata {
}