Forgive me for not understanding this if it's been said.
Why does the Angular implementation of its Dependency Injector use the injectables through a
constructor
?
I am used to seeing a DI
in various ways. Even a static method would make sense (If that exists sorry I haven't dug that deep yet, I'm a week into it so far).
Wouldn't it be easier or more logical to use it this way, more similar to a DI we see more often but still passing it in the constructor?:
// Non-Angular Example
@Component({})
class FooComponent {
public appState: AppState;
constructor(DI: DependencyInjector) {
this.appState = DI.get('AppState');
}
ngOnInit() {}
}
Angular is more like this, I'm not sure if it's for verbosity only, or if there are other reasons.
// Angular 2/4 Example
@Component({})
class BarComponent {
public appState: AppState;
constructor(appState: AppState,
router: Router,
etc: EtcSomething) {
}
ngOnInit() {}
I know Google had thought of this, I am just trying to understand the reasoning and/or benefit. Perhaps I woke up thinking about silly things and it's obvious and just went over my head but I missed it.
I hope what I'm asking makes sense, I just wonder why.