I have a fairly large Angular2 application with smart and dumb components, where all the smart components are hooked into a messaging bus:
class SomeSmartComponent {
constructor(private messageBuss: MessageBuss) {}
}
This is very repetitive and I would prefer to have:
class SomeSmartComponent extends SmartComponent {
constructor()
}
Ie. moving the common dependency into a parent class. I've tried the following:
class SmartComponent {
protected messageBuss: MessageBuss
constructor() {
let injector: Injector = Injector.resolveAndCreate([MessageBuss])
this.messageBuss = injector.get(MessageBuss)
}
}
The problem is that creates a new Injector and a new MessageBuss, where I need the same MessageBuss that is created by the root injector and injected into the service layer.
In other words I need to get access to the singleton MessageBuss created by the root injector without having it set in a constructor. Any help would be much appreciated.