From ace7145b4c1130fc504eda1a4aab262b0343f65f Mon Sep 17 00:00:00 2001 From: Developer Date: Tue, 2 Dec 2025 09:24:12 -0800 Subject: [PATCH] =?UTF-8?q?fix(reward-service):=20=E4=BF=AE=E5=A4=8D=20DI?= =?UTF-8?q?=20=E4=BE=9D=E8=B5=96=E6=B3=A8=E5=85=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: RewardCalculationService 无法解析依赖 - DomainModule 未导入 InfrastructureModule - service clients 使用 useClass 导致创建新实例时缺少依赖 解决方案: 1. DomainModule 导入 InfrastructureModule 2. InfrastructureModule 中: - 先注册具体的 client 类 (ReferralServiceClient, AuthorizationServiceClient) - 然后用 useExisting 提供 token 别名 - 这样确保使用同一个实例,包含所有依赖 参考: leaderboard-service 的修复方案 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../reward-service/src/domain/domain.module.ts | 2 ++ .../src/infrastructure/infrastructure.module.ts | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/backend/services/reward-service/src/domain/domain.module.ts b/backend/services/reward-service/src/domain/domain.module.ts index 14646ce4..4315537b 100644 --- a/backend/services/reward-service/src/domain/domain.module.ts +++ b/backend/services/reward-service/src/domain/domain.module.ts @@ -1,8 +1,10 @@ import { Module } from '@nestjs/common'; import { RewardCalculationService } from './services/reward-calculation.service'; import { RewardExpirationService } from './services/reward-expiration.service'; +import { InfrastructureModule } from '../infrastructure/infrastructure.module'; @Module({ + imports: [InfrastructureModule], providers: [ RewardCalculationService, RewardExpirationService, diff --git a/backend/services/reward-service/src/infrastructure/infrastructure.module.ts b/backend/services/reward-service/src/infrastructure/infrastructure.module.ts index 67cbebca..c13bf0ec 100644 --- a/backend/services/reward-service/src/infrastructure/infrastructure.module.ts +++ b/backend/services/reward-service/src/infrastructure/infrastructure.module.ts @@ -24,15 +24,19 @@ import { REFERRAL_SERVICE_CLIENT, AUTHORIZATION_SERVICE_CLIENT } from '../domain provide: REWARD_SUMMARY_REPOSITORY, useClass: RewardSummaryRepositoryImpl, }, + // Register concrete classes first + ReferralServiceClient, + AuthorizationServiceClient, + WalletServiceClient, + // Then provide token aliases using useExisting { provide: REFERRAL_SERVICE_CLIENT, - useClass: ReferralServiceClient, + useExisting: ReferralServiceClient, }, { provide: AUTHORIZATION_SERVICE_CLIENT, - useClass: AuthorizationServiceClient, + useExisting: AuthorizationServiceClient, }, - WalletServiceClient, ], exports: [ PrismaService,