rwadurian/backend/services/blockchain-service/src/infrastructure/infrastructure.module.ts

78 lines
2.2 KiB
TypeScript

import { Global, Module } from '@nestjs/common';
import { PrismaService } from './persistence/prisma/prisma.service';
import { RedisService, AddressCacheService } from './redis';
import { EventPublisherService, MpcEventConsumerService, WithdrawalEventConsumerService } from './kafka';
import { EvmProviderAdapter, AddressDerivationAdapter, MnemonicDerivationAdapter, RecoveryMnemonicAdapter, BlockScannerService } from './blockchain';
import { DomainModule } from '@/domain/domain.module';
import {
DEPOSIT_TRANSACTION_REPOSITORY,
MONITORED_ADDRESS_REPOSITORY,
BLOCK_CHECKPOINT_REPOSITORY,
TRANSACTION_REQUEST_REPOSITORY,
} from '@/domain/repositories';
import {
DepositTransactionRepositoryImpl,
MonitoredAddressRepositoryImpl,
BlockCheckpointRepositoryImpl,
TransactionRequestRepositoryImpl,
} from './persistence/repositories';
@Global()
@Module({
imports: [DomainModule],
providers: [
// 核心服务
PrismaService,
RedisService,
EventPublisherService,
MpcEventConsumerService,
WithdrawalEventConsumerService,
// 区块链适配器
EvmProviderAdapter,
AddressDerivationAdapter,
MnemonicDerivationAdapter,
RecoveryMnemonicAdapter,
BlockScannerService,
// 缓存服务
AddressCacheService,
// 仓储实现 (依赖倒置)
{
provide: DEPOSIT_TRANSACTION_REPOSITORY,
useClass: DepositTransactionRepositoryImpl,
},
{
provide: MONITORED_ADDRESS_REPOSITORY,
useClass: MonitoredAddressRepositoryImpl,
},
{
provide: BLOCK_CHECKPOINT_REPOSITORY,
useClass: BlockCheckpointRepositoryImpl,
},
{
provide: TRANSACTION_REQUEST_REPOSITORY,
useClass: TransactionRequestRepositoryImpl,
},
],
exports: [
PrismaService,
RedisService,
EventPublisherService,
MpcEventConsumerService,
WithdrawalEventConsumerService,
EvmProviderAdapter,
AddressDerivationAdapter,
MnemonicDerivationAdapter,
RecoveryMnemonicAdapter,
BlockScannerService,
AddressCacheService,
DEPOSIT_TRANSACTION_REPOSITORY,
MONITORED_ADDRESS_REPOSITORY,
BLOCK_CHECKPOINT_REPOSITORY,
TRANSACTION_REQUEST_REPOSITORY,
],
})
export class InfrastructureModule {}