Skip to content

Instantly share code, notes, and snippets.

@Stronhold
Created February 10, 2019 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stronhold/ef140d8a03e28b50c38be21e9216fdee to your computer and use it in GitHub Desktop.
Save Stronhold/ef140d8a03e28b50c38be21e9216fdee to your computer and use it in GitHub Desktop.
import { Injectable, Injector } from '@angular/core';
import { Executioner } from '../model/executioner';
import { ServiceLocator } from '../services/service-locator';
import { MessageTypeEnum } from '../model/message-type.enum';
@Injectable({
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