Advertisement
Guest User

services/

a guest
Feb 20th, 2020
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // serviceRegistry.js
  2. class ServiceRegistry {
  3.     constructor() {
  4.         if (!ServiceRegistry.instance) {
  5.             this.services = {};
  6.             ServiceRegistry.instance = this;
  7.         }
  8.  
  9.         return ServiceRegistry.instance;
  10.     }
  11. }
  12.  
  13. const instance = new ServiceRegistry();
  14. Object.freeze(instance)
  15.  
  16. module.exports = instance;
  17.  
  18. // Service.js
  19. class ServiceRegistry {
  20.     constructor() {
  21.         if (!ServiceRegistry.instance) {
  22.             this.services = {};
  23.             ServiceRegistry.instance = this;
  24.         }
  25.  
  26.         return ServiceRegistry.instance;
  27.     }
  28. }
  29.  
  30. const instance = new ServiceRegistry();
  31. Object.freeze(instance)
  32.  
  33. module.exports = instance;
  34.  
  35. // registry.js - utility functions
  36. class ServiceRegistry {
  37.     constructor() {
  38.         if (!ServiceRegistry.instance) {
  39.             this.services = {};
  40.             ServiceRegistry.instance = this;
  41.         }
  42.  
  43.         return ServiceRegistry.instance;
  44.     }
  45. }
  46.  
  47. const instance = new ServiceRegistry();
  48. Object.freeze(instance)
  49.  
  50. module.exports = instance;
  51.  
  52. // index.js
  53. class ServiceRegistry {
  54.     constructor() {
  55.         if (!ServiceRegistry.instance) {
  56.             this.services = {};
  57.             ServiceRegistry.instance = this;
  58.         }
  59.  
  60.         return ServiceRegistry.instance;
  61.     }
  62. }
  63.  
  64. const instance = new ServiceRegistry();
  65. Object.freeze(instance)
  66.  
  67. module.exports = instance;
  68.  
  69. // users/index.js
  70. const Service = require('../Service');
  71. const { registerService } = require('../registry');
  72.  
  73. class UsersService extends Service {
  74.     constructor() {
  75.         super('users');
  76.     }
  77.  
  78.     hello() {
  79.         console.log("hello from user");
  80.         this.moviesService.hello();
  81.         this.booksService.hello();
  82.     }
  83. }
  84.  
  85. registerService('users', UsersService, ['movies', 'books']);
  86.  
  87. module.exports = new UsersService();
  88.  
  89. // movies/index.js
  90. const Service = require('../Service');
  91. const { registerService } = require('../registry');
  92.  
  93. class MoviesService extends Service {
  94.     constructor() {
  95.         super('movies');
  96.     }
  97.  
  98.     hello() {
  99.         console.log('hello this is movie')
  100.     }
  101. }
  102.  
  103. registerService('movies', MoviesService);
  104.  
  105. module.exports = new MoviesService();
  106.  
  107. // books/index.js
  108. const Service = require('../Service');
  109. const { registerService } = require('../registry');
  110.  
  111. class BooksService extends Service {
  112.     constructor() {
  113.         super('books');
  114.     }
  115.  
  116.     hello() {
  117.         console.log('hello this is book')
  118.     }
  119. }
  120.  
  121. registerService('books', BooksService);
  122.  
  123. module.exports = new BooksService();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement