Is it a good practice to inject 'service' dependencies in @Input
properties? The service in this context is not a singleton instance managed at the root level but multiple instances of different implementations of the interface.
Consider the following example: In an Angular library, the ShapeComponent has a dependency on ShapeService (interface).
Component
@Component({
selector: 'ex-shape',
templateUrl: '..',
})
export class ShapeComponent {
constructor(shapeServiceCtor: ShapeService)
@Input shapeServiceInput: ShapeService;
}
A simple way to resolve the dependency is to set the input property as shown in the following code.
<ex-shape [shapeServiceInput]="rectangleShapeService" />
<ex-shape [shapeServiceInput]="ellipseShapeService" />
<ex-shape [shapeServiceInput]="polygonShapeService" />
Does the above approach hold good in resolving dependencies in Components?
If the input property approach is used then the services/dependencies have to the propagated to the child components in the same fashion. The downside of this approach is that the parent component will have to accept all the dependencies as input properties.
Are there any recommended approaches to inject and scope dependencies at the library level?