ing
This commit is contained in:
parent
4992e39e3f
commit
14f3fa4b1e
|
@ -1,28 +1,30 @@
|
||||||
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
import {
|
||||||
import ConfigurationDefinition from '@loafer/context/definition/ConfigurationDefinition';
|
PropertyType,
|
||||||
import { getInjectableDefinition } from '@loafer/pouches/util/metadata';
|
} from '@loafer/core/constants/types';
|
||||||
|
|
||||||
import GetAppContext from '@loafer/context';
|
import {
|
||||||
import { InjectableSterotype } from '@loafer/pouches/constants';
|
Decorator,
|
||||||
import DefaultPouchFactory from '@loafer/pouches/factory/implement/DefaultPouchFactory';
|
DecoratorHandler,
|
||||||
import PouchDefinitionRegistry from '@loafer/pouches/factory/registry/PouchDefinitionRegistry';
|
} from '@loafer/core/decorator';
|
||||||
import { validateQualifier } from '@loafer/pouches/util/qualifier';
|
|
||||||
|
|
||||||
const App = (qualifier?: string | symbol ) => createDecorator('App', {
|
import {
|
||||||
classDecorator: <TFunction extends Function>(target: TFunction): TFunction | void => {
|
Class,
|
||||||
let configurationDefinition = getInjectableDefinition(target.prototype, ConfigurationDefinition, false);
|
} from '@loafer/core/reflect';
|
||||||
if (undefined !== configurationDefinition) {
|
|
||||||
throw new Error('Cannot apply @Injectable or @Injectable stereotype decorator multiple times.');
|
|
||||||
}
|
|
||||||
|
|
||||||
configurationDefinition = getInjectableDefinition(target.prototype, ConfigurationDefinition, true);
|
import {
|
||||||
configurationDefinition.Stereotype = InjectableSterotype.APP;
|
InjectableAnnotation,
|
||||||
configurationDefinition.Qualifier = validateQualifier(target.prototype, qualifier);
|
} from '@loafer/pouches/decorator/Injectable';
|
||||||
|
|
||||||
return target;
|
export class AppAnnotation extends InjectableAnnotation implements DecoratorHandler {
|
||||||
},
|
public constructor(qualifier?: PropertyType) {
|
||||||
|
super(qualifier);
|
||||||
|
}
|
||||||
|
public onClassDecorator = <TFunction extends Function>(clazz: Class, target: TFunction): TFunction | void => {
|
||||||
|
console.log('App');
|
||||||
|
}
|
||||||
|
|
||||||
});
|
}
|
||||||
|
|
||||||
|
export const App = Decorator.create(AppAnnotation);
|
||||||
|
|
||||||
export default App;
|
export default App;
|
||||||
|
|
|
@ -1,28 +1,30 @@
|
||||||
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
import {
|
||||||
import ConfigurationDefinition from '@loafer/context/definition/ConfigurationDefinition';
|
PropertyType,
|
||||||
import { getInjectableDefinition } from '@loafer/pouches/util/metadata';
|
} from '@loafer/core/constants/types';
|
||||||
|
|
||||||
import GetAppContext from '@loafer/context';
|
import {
|
||||||
import { InjectableSterotype } from '@loafer/pouches/constants';
|
Decorator,
|
||||||
import DefaultPouchFactory from '@loafer/pouches/factory/implement/DefaultPouchFactory';
|
DecoratorHandler,
|
||||||
import PouchDefinitionRegistry from '@loafer/pouches/factory/registry/PouchDefinitionRegistry';
|
} from '@loafer/core/decorator';
|
||||||
import { validateQualifier } from '@loafer/pouches/util/qualifier';
|
|
||||||
|
|
||||||
const Configuration = (qualifier?: string | symbol ) => createDecorator('Configuration', {
|
import {
|
||||||
classDecorator: <TFunction extends Function>(target: TFunction): TFunction | void => {
|
Class,
|
||||||
let configurationDefinition: ConfigurationDefinition = getInjectableDefinition(target.prototype, ConfigurationDefinition, false);
|
} from '@loafer/core/reflect';
|
||||||
if (undefined !== configurationDefinition) {
|
|
||||||
throw new Error('Cannot apply @Injectable or @Injectable stereotype decorator multiple times.');
|
|
||||||
}
|
|
||||||
|
|
||||||
configurationDefinition = getInjectableDefinition(target.prototype, ConfigurationDefinition, true);
|
import {
|
||||||
configurationDefinition.Stereotype = InjectableSterotype.CONFIGURATION;
|
InjectableAnnotation,
|
||||||
configurationDefinition.Qualifier = validateQualifier(target.prototype, qualifier);
|
} from '@loafer/pouches/decorator/Injectable';
|
||||||
|
|
||||||
return target;
|
export class ConfigurationAnnotation extends InjectableAnnotation implements DecoratorHandler {
|
||||||
},
|
public constructor(qualifier?: PropertyType) {
|
||||||
|
super(qualifier);
|
||||||
|
}
|
||||||
|
public onClassDecorator = <TFunction extends Function>(clazz: Class, target: TFunction): TFunction | void => {
|
||||||
|
console.log('Configuration');
|
||||||
|
}
|
||||||
|
|
||||||
});
|
}
|
||||||
|
|
||||||
|
export const Configuration = Decorator.create(ConfigurationAnnotation);
|
||||||
|
|
||||||
export default Configuration;
|
export default Configuration;
|
||||||
|
|
|
@ -1,20 +1,36 @@
|
||||||
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
import {
|
||||||
|
ClassType,
|
||||||
|
PropertyType,
|
||||||
|
} from '@loafer/core/constants/types';
|
||||||
|
|
||||||
import ConfigurationDefinition from '@loafer/context/definition/ConfigurationDefinition';
|
import {
|
||||||
import PouchConfig from '@loafer/context/decorator/PouchConfig';
|
Decorator,
|
||||||
|
DecoratorHandler,
|
||||||
|
} from '@loafer/core/decorator';
|
||||||
|
|
||||||
import { getInjectableDefinition } from '@loafer/pouches/util/metadata';
|
import {
|
||||||
import { InjectableSterotype } from '@loafer/pouches/constants';
|
Class,
|
||||||
|
} from '@loafer/core/reflect';
|
||||||
|
|
||||||
const Pouch = (pouchConfig: PouchConfig = {}) => createDecorator('Pouch', {
|
export interface PouchConfig {
|
||||||
methodDecorator: (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any> => {
|
qualifier?: PropertyType;
|
||||||
let configurationDefinition: ConfigurationDefinition = getInjectableDefinition(target, ConfigurationDefinition, false);
|
type?: ClassType;
|
||||||
if (undefined === configurationDefinition || InjectableSterotype.CONFIGURATION !== configurationDefinition.Stereotype) {
|
}
|
||||||
throw new Error('Cannot apply @Pouch decorator on not @Configuration class.');
|
|
||||||
}
|
export class PouchAnnotation implements DecoratorHandler {
|
||||||
configurationDefinition.addPouch(propertyKey, pouchConfig);
|
private readonly Qualifier: PropertyType;
|
||||||
return descriptor;
|
private readonly Type: ClassType;
|
||||||
},
|
public constructor(config: PouchConfig = {}) {
|
||||||
});
|
this.Qualifier = config.qualifier;
|
||||||
|
this.Type = config.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public onMethodDecorator = <T>(clazz: Class, target: Object, propertyKey: PropertyType,
|
||||||
|
descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void => {
|
||||||
|
console.log('Pouch');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Pouch = Decorator.create(PouchAnnotation);
|
||||||
|
|
||||||
export default Pouch;
|
export default Pouch;
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
import { ClassType, PropertyType } from '@loafer/core/constants';
|
|
||||||
|
|
||||||
interface PouchConfig {
|
|
||||||
qualifier?: PropertyType;
|
|
||||||
type?: ClassType;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default PouchConfig;
|
|
|
@ -1,28 +0,0 @@
|
||||||
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
|
||||||
import InjectableDefinition from '@loafer/pouches/definition/InjectableDefinition';
|
|
||||||
import { getInjectableDefinition } from '@loafer/pouches/util/metadata';
|
|
||||||
|
|
||||||
import GetAppContext from '@loafer/context';
|
|
||||||
import { InjectableSterotype } from '@loafer/pouches/constants';
|
|
||||||
import { validateQualifier } from '@loafer/pouches/util/qualifier';
|
|
||||||
import DefaultPouchFactory from '@loafer/pouches/factory/implement/DefaultPouchFactory';
|
|
||||||
import PouchDefinitionRegistry from '@loafer/pouches/factory/registry/PouchDefinitionRegistry';
|
|
||||||
|
|
||||||
const Service = (qualifier?: string | symbol ) => createDecorator('Service', {
|
|
||||||
classDecorator: <TFunction extends Function>(target: TFunction): TFunction | void => {
|
|
||||||
let injectableDefinition: InjectableDefinition = getInjectableDefinition(target.prototype, InjectableDefinition, false);
|
|
||||||
if (undefined !== injectableDefinition) {
|
|
||||||
throw new Error('Cannot apply @Injectable or @Injectable stereotype decorator multiple times.');
|
|
||||||
}
|
|
||||||
|
|
||||||
injectableDefinition = getInjectableDefinition(target.prototype, InjectableDefinition, true);
|
|
||||||
injectableDefinition.Stereotype = InjectableSterotype.SERVICE;
|
|
||||||
injectableDefinition.Qualifier = validateQualifier(target.prototype, qualifier);
|
|
||||||
|
|
||||||
return target;
|
|
||||||
},
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
export default Service;
|
|
|
@ -1,13 +0,0 @@
|
||||||
import AppContext from '@loafer/context/AppContext';
|
|
||||||
import DefaultAppContext from '@loafer/context/implement/DefaultAppContext';
|
|
||||||
|
|
||||||
let _appContext: AppContext = undefined;
|
|
||||||
|
|
||||||
const GetAppContext = (): AppContext => {
|
|
||||||
if (undefined === _appContext) {
|
|
||||||
_appContext = new DefaultAppContext();
|
|
||||||
}
|
|
||||||
return _appContext;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default GetAppContext;
|
|
|
@ -21,20 +21,21 @@ export class Decorator {
|
||||||
reflection = new Reflection(type);
|
reflection = new Reflection(type);
|
||||||
Reflect.defineMetadata(ReflectConstants.REFLECT_META, reflection, type);
|
Reflect.defineMetadata(ReflectConstants.REFLECT_META, reflection, type);
|
||||||
}
|
}
|
||||||
|
let clazz: Class = reflection.getClass();
|
||||||
|
|
||||||
switch(decoratorType) {
|
switch(decoratorType) {
|
||||||
case DecoratorType.CLASS:
|
case DecoratorType.CLASS:
|
||||||
reflection.addClassAnnotation(annotation);
|
reflection.addClassAnnotation(annotation);
|
||||||
return annotation.onClassDecorator.apply(annotation, decoratorArgs);
|
return annotation.onClassDecorator.call(annotation, clazz, decoratorArgs[0]);
|
||||||
case DecoratorType.PROPERTY:
|
case DecoratorType.PROPERTY:
|
||||||
reflection.addPropertyAnnotation(annotation, decoratorArgs[1]);
|
reflection.addPropertyAnnotation(annotation, decoratorArgs[1]);
|
||||||
return annotation.onPropertyDecorator.apply(annotation, decoratorArgs);
|
return annotation.onPropertyDecorator.call(annotation, clazz, decoratorArgs[0], decoratorArgs[1]);
|
||||||
case DecoratorType.METHOD:
|
case DecoratorType.METHOD:
|
||||||
reflection.addMethodAnnotation(annotation, decoratorArgs[1]);
|
reflection.addMethodAnnotation(annotation, decoratorArgs[1]);
|
||||||
return annotation.onMethodDecorator.apply(annotation, decoratorArgs);
|
return annotation.onMethodDecorator.call(annotation, clazz, decoratorArgs[0], decoratorArgs[1], decoratorArgs[2]);
|
||||||
case DecoratorType.PARAMETER:
|
case DecoratorType.PARAMETER:
|
||||||
reflection.addParameterAnnotation(annotation, decoratorArgs[1], decoratorArgs[2]);
|
reflection.addParameterAnnotation(annotation, decoratorArgs[1], decoratorArgs[2]);
|
||||||
return annotation.onParameterDecorator.apply(annotation, decoratorArgs);
|
return annotation.onParameterDecorator.call(annotation, clazz, decoratorArgs[0], decoratorArgs[1], decoratorArgs[2]);
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,9 +1,18 @@
|
||||||
|
import {
|
||||||
|
ClassType,
|
||||||
|
PropertyType,
|
||||||
|
} from '@loafer/core/constants/types';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Class,
|
||||||
|
} from '@loafer/core/reflect';
|
||||||
|
|
||||||
export interface DecoratorHandler {
|
export interface DecoratorHandler {
|
||||||
onClassDecorator?: <TFunction extends Function>(target: TFunction) => TFunction | void;
|
onClassDecorator?: <TFunction extends Function>(clazz: Class, target: TFunction) => TFunction | void;
|
||||||
onPropertyDecorator?: (target: Object, propertyKey: string | symbol) => void;
|
onPropertyDecorator?: (clazz: Class, target: Object, propertyKey: PropertyType) => void;
|
||||||
onMethodDecorator?: <T>(target: Object, propertyKey: string | symbol,
|
onMethodDecorator?: <T>(clazz: Class, target: Object, propertyKey: PropertyType,
|
||||||
descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
|
descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
|
||||||
onParameterDecorator?: (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
|
onParameterDecorator?: (clazz: Class, target: Object, propertyKey: PropertyType, parameterIndex: number) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default DecoratorHandler;
|
export default DecoratorHandler;
|
||||||
|
|
|
@ -1,25 +1,47 @@
|
||||||
import InjectConfig from '@loafer/pouches/decorator/InjectConfig';
|
|
||||||
import InjectDefinition from '@loafer/pouches/definition/InjectDefinition';
|
|
||||||
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
|
||||||
import { getInjectDefinition } from '@loafer/pouches/util/metadata';
|
|
||||||
import {
|
import {
|
||||||
ClassType,
|
ClassType,
|
||||||
DESIGN_TYPE,
|
|
||||||
PropertyType,
|
PropertyType,
|
||||||
} from '@loafer/core/constants';
|
} from '@loafer/core/constants/types';
|
||||||
const Inject = (injectConfig: InjectConfig = {}) => createDecorator('Inject', {
|
|
||||||
propertyDecorator: (target: Object, propertyKey: string | symbol): void => {
|
|
||||||
let injectDefinition: InjectDefinition = getInjectDefinition(target, InjectDefinition, true);
|
|
||||||
injectDefinition.addInject(injectConfig, propertyKey);
|
|
||||||
},
|
|
||||||
parameterDecorator: (target: Object, propertyKey: string | symbol, parameterIndex: number): void => {
|
|
||||||
let injectDefinition: InjectDefinition = getInjectDefinition(target, InjectDefinition, true);
|
|
||||||
injectDefinition.addInject(injectConfig, propertyKey, parameterIndex);
|
|
||||||
},
|
|
||||||
|
|
||||||
});
|
import {
|
||||||
|
Decorator,
|
||||||
|
DecoratorHandler,
|
||||||
|
} from '@loafer/core/decorator';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Class,
|
||||||
|
} from '@loafer/core/reflect';
|
||||||
|
|
||||||
|
export interface InjectConfig {
|
||||||
|
qualifier?: PropertyType;
|
||||||
|
required?: boolean;
|
||||||
|
type?: ClassType;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class InjectAnnotation implements DecoratorHandler {
|
||||||
|
private readonly Qualifier: PropertyType;
|
||||||
|
private readonly Required: boolean;
|
||||||
|
private readonly Type: ClassType;
|
||||||
|
|
||||||
|
public constructor(config: InjectConfig = {}) {
|
||||||
|
this.Qualifier = config.qualifier;
|
||||||
|
this.Required = config.required;
|
||||||
|
this.Type = config.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public onPropertyDecorator = (clazz: Class, target: Object, propertyKey: PropertyType): void => {
|
||||||
|
console.log('Inject');
|
||||||
|
}
|
||||||
|
public onMethodDecorator = <T>(clazz: Class, target: Object, propertyKey: PropertyType,
|
||||||
|
descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void => {
|
||||||
|
console.log('Inject');
|
||||||
|
}
|
||||||
|
public onParameterDecorator = (clazz: Class, target: Object, propertyKey: PropertyType, parameterIndex: number): void => {
|
||||||
|
console.log('Inject');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Inject = Decorator.create(InjectAnnotation);
|
||||||
|
|
||||||
export default Inject;
|
export default Inject;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
import { ClassType, PropertyType } from '@loafer/core/constants';
|
|
||||||
|
|
||||||
interface InjectConfig {
|
|
||||||
qualifier?: PropertyType;
|
|
||||||
required?: boolean;
|
|
||||||
clazz?: ClassType;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default InjectConfig;
|
|
|
@ -1,26 +1,28 @@
|
||||||
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
import {
|
||||||
import InjectableDefinition from '@loafer/pouches/definition/InjectableDefinition';
|
PropertyType,
|
||||||
import { getInjectableDefinition } from '@loafer/pouches/util/metadata';
|
} from '@loafer/core/constants/types';
|
||||||
|
|
||||||
import GetAppContext from '@loafer/context';
|
import {
|
||||||
import { validateQualifier } from '@loafer/pouches/util/qualifier';
|
Decorator,
|
||||||
import DefaultPouchFactory from '@loafer/pouches/factory/implement/DefaultPouchFactory';
|
DecoratorHandler,
|
||||||
import PouchDefinitionRegistry from '@loafer/pouches/factory/registry/PouchDefinitionRegistry';
|
} from '@loafer/core/decorator';
|
||||||
|
|
||||||
const Injectable = (qualifier?: string | symbol ) => createDecorator('Injectable', {
|
import {
|
||||||
classDecorator: <TFunction extends Function>(target: TFunction): TFunction | void => {
|
Class,
|
||||||
let injectableDefinition: InjectableDefinition = getInjectableDefinition(target.prototype, InjectableDefinition, false);
|
} from '@loafer/core/reflect';
|
||||||
if (undefined !== injectableDefinition) {
|
|
||||||
throw new Error('Cannot apply @Injectable decorator multiple times.');
|
|
||||||
}
|
|
||||||
|
|
||||||
injectableDefinition = getInjectableDefinition(target.prototype, InjectableDefinition, true);
|
export class InjectableAnnotation implements DecoratorHandler {
|
||||||
injectableDefinition.Qualifier = validateQualifier(target.prototype, qualifier);
|
private readonly Qualifier: PropertyType;
|
||||||
|
|
||||||
return target;
|
public constructor(qualifier?: PropertyType) {
|
||||||
},
|
this.Qualifier = qualifier;
|
||||||
|
}
|
||||||
|
public onClassDecorator = <TFunction extends Function>(clazz: Class, target: TFunction): TFunction | void => {
|
||||||
|
console.log('Injectable');
|
||||||
|
}
|
||||||
|
|
||||||
});
|
}
|
||||||
|
|
||||||
|
export const Injectable = Decorator.create(InjectableAnnotation);
|
||||||
|
|
||||||
export default Injectable;
|
export default Injectable;
|
||||||
|
|
|
@ -1,16 +1,23 @@
|
||||||
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
import {
|
||||||
import InjectableDefinition from '@loafer/pouches/definition/InjectableDefinition';
|
PropertyType,
|
||||||
import { getInjectableDefinition } from '@loafer/pouches/util/metadata';
|
} from '@loafer/core/constants/types';
|
||||||
|
|
||||||
const PostConstruct = createDecorator('PostConstruct', {
|
import {
|
||||||
methodDecorator: (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any> => {
|
Decorator,
|
||||||
let injectableDefinition = getInjectableDefinition(target, InjectableDefinition, false);
|
DecoratorHandler,
|
||||||
if (undefined === injectableDefinition) {
|
} from '@loafer/core/decorator';
|
||||||
throw new Error('Cannot apply @PostConstruct decorator on the not @Injectable or @Injectable stereotype class.');
|
|
||||||
}
|
import {
|
||||||
injectableDefinition.addPostConstruct(propertyKey);
|
Class,
|
||||||
return descriptor;
|
} from '@loafer/core/reflect';
|
||||||
},
|
|
||||||
});
|
export class PostConstructAnnotation implements DecoratorHandler {
|
||||||
|
public onMethodDecorator = <T>(clazz: Class, target: Object, propertyKey: PropertyType,
|
||||||
|
descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void => {
|
||||||
|
console.log('PostConstruct');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const PostConstruct = Decorator.create(PostConstructAnnotation);
|
||||||
|
|
||||||
export default PostConstruct;
|
export default PostConstruct;
|
||||||
|
|
|
@ -1,16 +1,23 @@
|
||||||
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
import {
|
||||||
import InjectableDefinition from '@loafer/pouches/definition/InjectableDefinition';
|
PropertyType,
|
||||||
import { getInjectableDefinition } from '@loafer/pouches/util/metadata';
|
} from '@loafer/core/constants/types';
|
||||||
|
|
||||||
const PreDestroy = createDecorator('PreDestroy', {
|
import {
|
||||||
methodDecorator: (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any> => {
|
Decorator,
|
||||||
let injectableDefinition = getInjectableDefinition(target, InjectableDefinition, false);
|
DecoratorHandler,
|
||||||
if (undefined === injectableDefinition) {
|
} from '@loafer/core/decorator';
|
||||||
throw new Error('Cannot apply @PreDestroy decorator on the not @Injectable or @Injectable stereotype class.');
|
|
||||||
}
|
import {
|
||||||
injectableDefinition.addPreDestroy(propertyKey);
|
Class,
|
||||||
return descriptor;
|
} from '@loafer/core/reflect';
|
||||||
},
|
|
||||||
});
|
export class PreDestroyAnnotation implements DecoratorHandler {
|
||||||
|
public onMethodDecorator = <T>(clazz: Class, target: Object, propertyKey: PropertyType,
|
||||||
|
descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void => {
|
||||||
|
console.log('PreDestroy');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const PreDestroy = Decorator.create(PreDestroyAnnotation);
|
||||||
|
|
||||||
export default PreDestroy;
|
export default PreDestroy;
|
||||||
|
|
|
@ -1,17 +1,28 @@
|
||||||
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
import {
|
||||||
import InjectableDefinition from '@loafer/pouches/definition/InjectableDefinition';
|
PropertyType,
|
||||||
import { getInjectableDefinition } from '@loafer/pouches/util/metadata';
|
} from '@loafer/core/constants/types';
|
||||||
import { PouchScope } from '@loafer/pouches/constants';
|
|
||||||
|
|
||||||
const Scope = (scope: PouchScope = PouchScope.SINGLETON) => createDecorator('Scope', {
|
import {
|
||||||
classDecorator: <TFunction extends Function>(target: TFunction): TFunction | void => {
|
Decorator,
|
||||||
let injectableDefinition = getInjectableDefinition(target.prototype, InjectableDefinition, false);
|
DecoratorHandler,
|
||||||
if (undefined === injectableDefinition) {
|
} from '@loafer/core/decorator';
|
||||||
throw new Error('Cannot apply @Scope decorator on the not @Injectable or @Injectable stereotype class.');
|
|
||||||
}
|
import {
|
||||||
injectableDefinition.Scope = scope;
|
Class,
|
||||||
return target;
|
} from '@loafer/core/reflect';
|
||||||
},
|
|
||||||
});
|
export class ScopeAnnotation implements DecoratorHandler {
|
||||||
|
private readonly Qualifier: PropertyType;
|
||||||
|
|
||||||
|
public constructor(qualifier?: PropertyType) {
|
||||||
|
this.Qualifier = qualifier;
|
||||||
|
}
|
||||||
|
public onClassDecorator = <TFunction extends Function>(clazz: Class, target: TFunction): TFunction | void => {
|
||||||
|
console.log('Scope');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Scope = Decorator.create(ScopeAnnotation);
|
||||||
|
|
||||||
export default Scope;
|
export default Scope;
|
||||||
|
|
|
@ -1,17 +1,33 @@
|
||||||
import InjectDefinition from '@loafer/pouches/definition/InjectDefinition';
|
import {
|
||||||
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
ClassType,
|
||||||
import { getInjectDefinition } from '@loafer/pouches/util/metadata';
|
PropertyType,
|
||||||
|
} from '@loafer/core/constants/types';
|
||||||
|
|
||||||
const Value = (value: string) => createDecorator('Value', {
|
import {
|
||||||
propertyDecorator: (target: Object, propertyKey: string | symbol): void => {
|
Decorator,
|
||||||
let injectDefinition: InjectDefinition = getInjectDefinition(target, InjectDefinition, true);
|
DecoratorHandler,
|
||||||
injectDefinition.addValue(value, propertyKey);
|
} from '@loafer/core/decorator';
|
||||||
},
|
|
||||||
parameterDecorator: (target: Object, propertyKey: string | symbol, parameterIndex: number): void => {
|
|
||||||
let injectDefinition: InjectDefinition = getInjectDefinition(target, InjectDefinition, true);
|
|
||||||
injectDefinition.addValue(value, propertyKey, parameterIndex);
|
|
||||||
},
|
|
||||||
|
|
||||||
});
|
import {
|
||||||
|
Class,
|
||||||
|
} from '@loafer/core/reflect';
|
||||||
|
|
||||||
|
export class ValueAnnotation implements DecoratorHandler {
|
||||||
|
private readonly Value: PropertyType;
|
||||||
|
|
||||||
|
public constructor(value: PropertyType) {
|
||||||
|
this.Value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public onPropertyDecorator = (clazz: Class, target: Object, propertyKey: PropertyType): void => {
|
||||||
|
console.log('Value');
|
||||||
|
}
|
||||||
|
public onParameterDecorator = (clazz: Class, target: Object, propertyKey: PropertyType, parameterIndex: number): void => {
|
||||||
|
console.log('Value');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Value = Decorator.create(ValueAnnotation);
|
||||||
|
|
||||||
export default Value;
|
export default Value;
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
export * from './inject';
|
|
||||||
export * from './injectable';
|
|
|
@ -1,11 +0,0 @@
|
||||||
import { ClassType } from '@loafer/core/constants';
|
|
||||||
import getClassMetadata, {
|
|
||||||
MetadataDefinable,
|
|
||||||
} from '@loafer/core/util/metadata/getClassMetadata';
|
|
||||||
|
|
||||||
import { POUCH_INJECT_DEFINITION } from '@loafer/pouches/constants';
|
|
||||||
import InjectDefinition from '@loafer/pouches/definition/InjectDefinition';
|
|
||||||
|
|
||||||
export const getInjectDefinition =
|
|
||||||
<T>(clazz: ClassType, definitionType: MetadataDefinable<T>, isCreate: boolean = false) =>
|
|
||||||
getClassMetadata(clazz, POUCH_INJECT_DEFINITION, definitionType, isCreate);
|
|
|
@ -1,9 +0,0 @@
|
||||||
import { ClassType } from '@loafer/core/constants';
|
|
||||||
import getClassMetadata, {
|
|
||||||
MetadataDefinable,
|
|
||||||
} from '@loafer/core/util/metadata/getClassMetadata';
|
|
||||||
import { POUCH_INJECTABLE_DEFINITION } from '@loafer/pouches/constants';
|
|
||||||
import InjectableDefinition from '@loafer/pouches/definition/InjectableDefinition';
|
|
||||||
|
|
||||||
export const getInjectableDefinition = <T>(clazz: ClassType, definitionType: MetadataDefinable<T>, isCreate: boolean = false) =>
|
|
||||||
getClassMetadata(clazz, POUCH_INJECTABLE_DEFINITION, definitionType, isCreate);
|
|
Loading…
Reference in New Issue
Block a user