小编Gab*_*ile的帖子

在 NestJs 中,如何根据其接口注入服务?

我有下一个模块:payment.module.ts

@Module({
  controllers: [PaymentController],
})
export class PaymentModule {}
Run Code Online (Sandbox Code Playgroud)

在下一个服务中,我想访问基于接口的服务

支付服务.ts

export class PaymentService {
   constructor(private readonly notificationService: NotificationInterface,
}
Run Code Online (Sandbox Code Playgroud)

通知.interface.ts

export interface NotificationInterface {
  // some method definitions
}
Run Code Online (Sandbox Code Playgroud)

通知.service.ts

@Injectable()
export class NotificationService implements NotificationInterface {
  // some implemented methods
}
Run Code Online (Sandbox Code Playgroud)

问题是我如何注入NotificationService基于NotificationInterface

javascript node.js typescript ecmascript-6 nestjs

3
推荐指数
2
解决办法
4243
查看次数

标签 统计

ecmascript-6 ×1

javascript ×1

nestjs ×1

node.js ×1

typescript ×1