In my BaseComponent
, I have some dependencies injected. The first dependency, EntityService
, is essential and correctly implemented.
However, the AnyOtherService
is only utilized within the abstract BaseComponent
. Instead of injecting it into the ChildComponent
where it remains unused, I prefer to have it injected solely into the BaseComponent
.
Why must it pass through the ChildComponent
before reaching the BaseComponent
? A better approach would be to keep it encapsulated within the BaseComponent
.
base.component.ts
export abstract class BaseComponent {
constructor(
protected entityService: EntityService,
// protected anyOtherService: AnyOtherService // @todo add this
) {
}
}
child.component.ts
@Component()
export class ChildComponent extends BaseComponent {
constructor(
private firstService: FirstService,
private secondService: SecondService,
protected anyOtherService: AnyOtherService // @todo remove this
) {
super(
firstService,
anyOtherService // @todo remove this
);
}
}