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.

ServiceDecorator.ts 989B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { Injector } from "./Injector";
  2. import { Type, GenericClassDecorator } from "./Util";
  3. import { FrontworkComponent } from "../Types/FrontworkComponent";
  4. /**
  5. * @returns {GenericClassDecorator<Type<any>>}
  6. * @constructor
  7. */
  8. export const Injectable = (_interface?: Type<any>) : GenericClassDecorator<Type<any>> => {
  9. return (target: Type<any>) => {
  10. Injector.modules.push({
  11. implements: _interface,
  12. implementation: target
  13. })
  14. }
  15. }
  16. /**
  17. * @returns {GenericClassDecorator<Type<any>>}
  18. * @constructor
  19. */
  20. export const RootComponent = (config : {
  21. injectable : Type<any>
  22. injects : Type<FrontworkComponent>[]
  23. }) : GenericClassDecorator<Type<any>> => {
  24. return (target: Type<any>) => {
  25. Injector.rootModules = config.injects
  26. Injector.rootInterface = config.injectable
  27. Injector.root = target
  28. }
  29. }
  30. export const Inject = (type: any) => {
  31. return function (_this, key) {
  32. Injector.injectionQueue.push({what: type, target: _this, where:key})
  33. }
  34. }