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 777B

1234567891011121314151617181920212223242526272829
  1. import { Injector } from "./Injector";
  2. import { Type, GenericClassDecorator, Constructor } from "./Internals";
  3. /**
  4. * @returns {GenericClassDecorator<Type<any>>}
  5. * @constructor
  6. */
  7. export function Singleton(config?: {
  8. interface?: Constructor<any>,
  9. initializationPriority?: number
  10. }): GenericClassDecorator<Type<any>> {
  11. return (clazz: Type<any>) => {
  12. Injector['singletonDefinitions'].push({
  13. initializationPriority: config ?. initializationPriority,
  14. ctor: clazz
  15. })
  16. if(config && config.interface){
  17. Injector['tokenLookupTable'][config.interface.name] = clazz
  18. }
  19. }
  20. }
  21. export function Inject(token: Constructor<any>) {
  22. return function (receiver: Object, key: string) {
  23. Injector['injectionQueue'].push({ token, receiver, key })
  24. }
  25. }