You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Decorator.ts 619B

123456789101112131415161718192021
  1. import { Injector } from "./Injector";
  2. import { Type, GenericClassDecorator, Constructor } from "./Types";
  3. /**
  4. * @returns {GenericClassDecorator<Type<any>>}
  5. * @constructor
  6. */
  7. export function Singleton(_interface?: Constructor<any>): GenericClassDecorator<Type<any>> {
  8. return (clazz: Type<any>) => {
  9. Injector['modules'].push({
  10. implements: _interface ?? clazz,
  11. ctor: clazz
  12. })
  13. }
  14. }
  15. export function Inject(clazz: Constructor<any>) {
  16. return function (prototype: Object, key: string) {
  17. Injector['injectionQueue'].push({ injectionType: clazz, prototype: prototype, injectIntoKey: key })
  18. }
  19. }