import { Inject , Injectable , InjectionToken , OnDestroy } from '@angular/core' ; import { SettingsContext } from './settings-context' ; export const SETTINGS_REGISTRATION = new InjectionToken < SettingsContext < any > [ ] > ( 'SettingsRegistration' ) ; @ Injectable ( ) export class SettingsRegistry implements OnDestroy { readonly settingsMap = new Map < string , SettingsContext < any > > ( ) ; constructor ( @ Inject ( SETTINGS_REGISTRATION ) registration ) { registration . forEach ( ( context ) => { this . settingsMap . set ( context . id , context ) ; } ) ; } ngOnDestroy ( ) { this . settingsMap . clear ( ) ; } getSettings ( ) { return [ ... this . settingsMap . values ( ) ] ; } }