将服务Singleton实例注射到没有构造函数的另一个服务中



我有:

  • baseService 将用作父级
  • UTILSERVICE 用于实用程序功能
  • aservice 是基础服务的子类(从碱服务延伸)
  • bservice 也是baseService的子类

我想注入 utilservice singleton实例to baseService 不使用constructor(constructor(baseService:baseService:baseService:baseService:baseService:baseService:baseService:baseService:baseService:baseService:){}),因为如果不是,则 aservice and bservice 需要通过 UTILSERVICE singleton实例作为参数为参数,称为 UTILSERVICE UTILSERVICE >的构造函数(super(grimonments))显然是一个冗余步骤。因此,我想知道是否有其他方法可以在 aservice/bservice constructor的super Call中使用 UTILSERVICE singleton实例。预先感谢。

我不知道它是否将是Singelton,但是您可以使用

注入服务
constructor(private inj: Injector) { }
....where you need..
const customService= this.inj.get(CustomService)

最新更新