简单场景:
我有多个实现通用接口的服务。所有这些服务都在该bootstrap
方法中注册。
现在我想要另一个服务,它注入所有实现公共接口的注册服务。
IE
export interface MyInterface {
foo(): void;
}
export class Service1 implements MyInterface {
foo() { console.out("bar"); }
}
export class Service2 implements MyInterface {
foo() { console.out("baz"); }
}
export class CollectorService {
constructor(services:MyInterface[]) {
services.forEach(s => s.foo());
}
}
这有可能吗?