NestJS 依赖注入和 TransformPipe
NestJS dependency injection and TransformPipe
我创建了一个模块 A,它有一个导出的提供程序 AService
。模块 B 导入模块 A 并具有导出的 BTransformPipe
提供程序,该提供程序使用 AService
。现在,我的理解是,当我在模块 C 中导入模块 B 时,我应该能够在模块 C 中声明的控制器中使用 BTransformPipe
,而无需声明任何进一步的依赖关系,但 NestJS 无法注入 AService
在模块 C 中使用的 BTransformPipe
中。我是否遗漏了什么?
增强子并没有真正进入 providers
数组,也没有从那里解析。如果您在 CModule
中使用 BTransformPipe
,那么 CModule
需要访问 BTransformPipe
的所有依赖项。为了便于跟踪,您的 BModule
可以在 imports
和 exports
中包含 AModule
,然后您只需要包含 BModule
在您要使用 BTransformPipe
.
的模块的 imports
中
我创建了一个模块 A,它有一个导出的提供程序 AService
。模块 B 导入模块 A 并具有导出的 BTransformPipe
提供程序,该提供程序使用 AService
。现在,我的理解是,当我在模块 C 中导入模块 B 时,我应该能够在模块 C 中声明的控制器中使用 BTransformPipe
,而无需声明任何进一步的依赖关系,但 NestJS 无法注入 AService
在模块 C 中使用的 BTransformPipe
中。我是否遗漏了什么?
增强子并没有真正进入 providers
数组,也没有从那里解析。如果您在 CModule
中使用 BTransformPipe
,那么 CModule
需要访问 BTransformPipe
的所有依赖项。为了便于跟踪,您的 BModule
可以在 imports
和 exports
中包含 AModule
,然后您只需要包含 BModule
在您要使用 BTransformPipe
.
imports
中