I have a service with multiple instances, that I provide multiple.
{ provide: MyAbstractService, useClass: MyServiceA, multi: true },
{ provide: MyAbstractService, useClass: MyServiceB, multi: true },
For reasons I don't further want to name, I want to use the new inject function to inject those services instead of constructor injection.
Before Angular 14 I would have done that in constructor:
@Inject(MyAbstractService) myServices: MyAbstractService[],
I expected this to work, but it doesn't:
private myServices: MyAbstractService[] = inject(MyAbstractService);
inject seems to never return an array, hence I can't assign it to an array type. How to tell inject that I expect an array of services here? Following seems to work, but also seems dirty:
private myServices: MyAbstractService[] = inject(MyAbstractService) as unknown as MyAbstractService[];
See stackblitz example: https://stackblitz.com/edit/angular-ivy-gayhxw?file=src/app/app.component.ts