jeudi 21 septembre 2017

Enumerate all components in app implementing specific interface

I have an interface (could be converted to an abstract class, if needed):

export interface INavigationRootComponent {
    ...
}

And I have a service that needs to have a list of components in the app implementing INavigationRootComponent:

@Injectable()
export class NavigationService {
    private navigationComponents: INavigationRootComponent[];
}

Is it possible to enumerate all components in app implementing that specific interface INavigationRootComponent preferably at runtime, so there would be no need for a module containing NavigationService to have hardcoded dependencies on every such component? If yes, how?

If it would be an app running on CLR, I'd queried all types in the app assembly derived from the INavigationRootComponent interface and enumerated them. But I'm not sure if and how it could be done in Angular.





Aucun commentaire:

Enregistrer un commentaire