【问题标题】:TypeDI not detecting Services from local external packageTypeDI 未检测到来自本地外部包的服务
【发布时间】:2022-11-09 14:19:29
【问题描述】:

我有一个单声道回购项目,它由两个(lerna 构建的)包BaseLibs 组成。我正在尝试使用 TypeDi 依赖注入,并且 Libs 项目中标有 Service() 装饰器的类未在 Base 容器中创建:

库/example.js

    import { Service } from 'typedi';

    @Service()
    export class ExampleService{
        //...do stuff
    }

库/index.js

    import { ExampleService } from './example';

    export { ExampleService };

基础/index.js

    import { Container } from 'typedi';
    import { ExampleService } from 'Libs'

    //Error thrown here "Service with "MaybeConstructable<ExampleService>" identifier was not found in the container. Register it before usage via explicitly calling the "Container.set" function or using the "@Service()" decorator."
    const xmpl = Container.get(ExampleService)

有没有办法注入这些类而不显式将所有类依赖项导入Base 项目并使用Container.set()

【问题讨论】:

    标签: typescript dependency-injection lerna typedi


    【解决方案1】:

    你找到解决方案了吗?我面临同样的问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-14
      • 1970-01-01
      • 1970-01-01
      • 2016-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-31
      相关资源
      最近更新 更多