I've been looking if it's possible for TSyringe to inject all classes that implements some interface (or extends from an abstract class), like this:
@injectable()
export interface IService {
foo(): void;
}
@injectable()
export class Service1 implements IService {
foo() { console.out("bar"); }
}
@injectable()
export class Service2 implements IService {
foo() { console.out("baz"); }
}
export class CollectorService {
constructor(
@inject('Service')
services: IService[]
) {
services.forEach(s => s.foo());
}
}
I just started using TSyringe a month ago, so I'm not familiar with all features and I don't know how to register this kind of dependency (if it's possible to achieve what I'm proposing) in the DI container.
I'm trying to mimic Spring @Autowire
annotation.