【发布时间】:2018-08-08 10:15:19
【问题描述】:
我想通过 Nest.js 依赖注入服务创建一个动态加载的类的实例。
在 Angular 中我会使用 Injector.create,在 Nest.js 中的等价物是什么?
【问题讨论】:
标签: node.js typescript nestjs
我想通过 Nest.js 依赖注入服务创建一个动态加载的类的实例。
在 Angular 中我会使用 Injector.create,在 Nest.js 中的等价物是什么?
【问题讨论】:
标签: node.js typescript nestjs
首先你应该得到一个引用当前模块的ModuleRef,然后使用它的“get”方法来获取一个实例。
@Injectable()
export class AppletService {
files: FileService;
constructor(
private moduleRef: ModuleRef,
) {
this.files = moduleRef.get(FileService);
}
}
【讨论】: