fix(reward-service): 修复 DI 依赖注入错误
问题: 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 <noreply@anthropic.com>
This commit is contained in:
parent
afdaa888ec
commit
ace7145b4c
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue