NestJs | 依赖注入报错Nest can't resolve dependencies of the UsersController (?). Pleasemake sure that the

本文解决了NestJS中UsersController依赖注入失败的问题,原因是构造函数中使用了接口而非类声明,导致NestJS无法正确解析依赖。通过使用装饰器注入特定的服务实例,问题得以解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[ExceptionHandler] Nest can't resolve dependencies of the UsersController (?). Pleasemake sure that the argument at index [0] is available in the UsersModule context. +0ms
Error: Nest can't resolve dependencies of the UsersController (?). Please make sure that the argument at index [0] is available in the UsersModule context.

构造函数注入依赖时用了接口声明,而不是类声明,导致nestjs无法获取依赖项。

解决办法,注入依赖时使用装饰器解构

@Inject('UsersService') private UsersService: User.Service

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值