Skip to content

依赖查找

除了依赖注入,Vona 还提供了依赖查找。在 Vona 中,推荐使用依赖查找,因为依赖查找可以让代码更加简洁、直观

本模块查找

假设我们要在模块 home-base 的 ControllerMenu 中查找本模块提供的 ServiceMenu,代码如下:

typescript
export class ControllerMenu {
  async test() {
    return await this.scope.service.menu.retrieveMenus('');
  }
}
  • 通过this.scope获取本模块的 scope 对象,从而找到本模块提供的 service

跨模块查找

假设我们要在模块 home-index 的 ControllerHome 中查找模块 home-base 提供的 ServiceMenu,代码如下:

typescript
export class ControllerMenu {
  async test() {
    return await this.$scope.homeBase.service.menu.retrieveMenus('');
  }
}
  • 通过this.$scope.homeBase获取模块 home-base 的 scope 对象,从而找到模块 home-base 提供的 service

查找全局bean

假设我们要在模块 home-index 的 ControllerHome 中查找模块 a-jwt 提供的全局 beanBeanJwt,代码如下:

typescript
export class ControllerMenu {
  async test() {
    return await this.bean.jwt.create({});
  }
}
  • 通过this.bean获取 app bean 容器,从而找到全局 bean

基于 MIT 许可发布