【发布时间】:2022-11-09 14:19:29
【问题描述】:
我有一个单声道回购项目,它由两个(lerna 构建的)包Base 和Libs 组成。我正在尝试使用 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