Skip to content

Instantly share code, notes, and snippets.

Created February 10, 2019 13:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import { Injectable, Injector } from '@angular/core';
import { Executioner } from '../model/executioner';
import { ServiceLocator } from '../services/service-locator';
import { MessageTypeEnum } from '../model/message-type.enum';
providedIn: 'root'
export class RegistryService {
private static INSTANCE: RegistryService | undefined = null;
private registry: Map<MessageTypeEnum, Executioner> = new Map();
private constructor(private _injector: Injector) {
public static getRegistry(): RegistryService {
if (!this.INSTANCE) {
this.INSTANCE = new RegistryService(ServiceLocator.injector);
return this.INSTANCE;
register(key: MessageTypeEnum, value: Executioner): void {
this.registry.set(key, value);
getRegister(key: MessageTypeEnum): Executioner {
if (this.registry.has(key))
return this.registry.get(key);
throw Error(`No service registered for key ${key}`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment