Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想通过 Nest.js 依赖注入服务创建一个动态加载的类的实例。
在 Angular 中我会使用Injector.create,在 Nest.js 中的等价物是什么?
Injector.create
首先你应该得到一个引用当前模块的 ModuleRef,然后使用它的“get”方法来获取一个实例。
@Injectable() export class AppletService { files: FileService; constructor( private moduleRef: ModuleRef, ) { this.files = moduleRef.get(FileService); } }