diff --git a/backend/services/identity-service/src/app.module.ts b/backend/services/identity-service/src/app.module.ts index 9e927b98..4a2effe8 100644 --- a/backend/services/identity-service/src/app.module.ts +++ b/backend/services/identity-service/src/app.module.ts @@ -15,6 +15,8 @@ import { ReferralsController } from '@/api/controllers/referrals.controller'; // Application Services import { UserApplicationService } from '@/application/services/user-application.service'; import { TokenService } from '@/application/services/token.service'; +import { BlockchainWalletHandler } from '@/application/event-handlers/blockchain-wallet.handler'; +import { MpcKeygenCompletedHandler } from '@/application/event-handlers/mpc-keygen-completed.handler'; // Domain Services import { @@ -30,6 +32,7 @@ import { MpcKeyShareRepositoryImpl } from '@/infrastructure/persistence/reposito import { RedisService } from '@/infrastructure/redis/redis.service'; import { EventPublisherService } from '@/infrastructure/kafka/event-publisher.service'; import { MpcEventConsumerService } from '@/infrastructure/kafka/mpc-event-consumer.service'; +import { BlockchainEventConsumerService } from '@/infrastructure/kafka/blockchain-event-consumer.service'; import { SmsService } from '@/infrastructure/external/sms/sms.service'; import { BlockchainClientService } from '@/infrastructure/external/blockchain/blockchain-client.service'; import { MpcClientService, MpcWalletService } from '@/infrastructure/external/mpc'; @@ -53,6 +56,7 @@ import { JwtAuthGuard } from '@/shared/guards/jwt-auth.guard'; RedisService, EventPublisherService, MpcEventConsumerService, + BlockchainEventConsumerService, SmsService, MpcClientService, MpcWalletService, @@ -64,6 +68,7 @@ import { JwtAuthGuard } from '@/shared/guards/jwt-auth.guard'; RedisService, EventPublisherService, MpcEventConsumerService, + BlockchainEventConsumerService, SmsService, MpcClientService, MpcWalletService, @@ -92,7 +97,13 @@ export class DomainModule {} // ============ Application Module ============ @Module({ imports: [DomainModule, InfrastructureModule], - providers: [UserApplicationService, TokenService], + providers: [ + UserApplicationService, + TokenService, + // Event Handlers - 通过注入到 UserApplicationService 来确保它们被初始化 + BlockchainWalletHandler, + MpcKeygenCompletedHandler, + ], exports: [UserApplicationService, TokenService], }) export class ApplicationModule {} diff --git a/backend/services/identity-service/src/application/services/user-application.service.ts b/backend/services/identity-service/src/application/services/user-application.service.ts index 092abb7e..9d2b1d90 100644 --- a/backend/services/identity-service/src/application/services/user-application.service.ts +++ b/backend/services/identity-service/src/application/services/user-application.service.ts @@ -16,6 +16,8 @@ import { SmsService } from '@/infrastructure/external/sms/sms.service'; import { EventPublisherService } from '@/infrastructure/kafka/event-publisher.service'; import { BlockchainClientService } from '@/infrastructure/external/blockchain/blockchain-client.service'; import { MpcWalletService } from '@/infrastructure/external/mpc'; +import { BlockchainWalletHandler } from '../event-handlers/blockchain-wallet.handler'; +import { MpcKeygenCompletedHandler } from '../event-handlers/mpc-keygen-completed.handler'; import { ApplicationError } from '@/shared/exceptions/domain.exception'; import { generateRandomIdentity } from '@/shared/utils'; import { MpcKeygenRequestedEvent } from '@/domain/events'; @@ -48,6 +50,9 @@ export class UserApplicationService { private readonly redisService: RedisService, private readonly smsService: SmsService, private readonly eventPublisher: EventPublisherService, + // 注入事件处理器以确保它们被 NestJS 实例化并执行 onModuleInit + private readonly blockchainWalletHandler: BlockchainWalletHandler, + private readonly mpcKeygenCompletedHandler: MpcKeygenCompletedHandler, ) {} /**