import { Module, Provider } from '@nestjs/common'; import { CreateAuthenticationGrpcController } from './interface/grpc-controllers/create-authentication.grpc.controller'; import { CreateAuthenticationService } from './core/application/commands/create-authentication/create-authentication.service'; import { AuthenticationMapper } from './authentication.mapper'; import { AUTHENTICATION_REPOSITORY, USERNAME_REPOSITORY, } from './authentication.di-tokens'; import { AuthenticationRepository } from './infrastructure/authentication.repository'; import { PrismaService } from './infrastructure/prisma.service'; import { CqrsModule } from '@nestjs/cqrs'; import { DeleteAuthenticationGrpcController } from './interface/grpc-controllers/delete-authentication.grpc.controller'; import { DeleteAuthenticationService } from './core/application/commands/delete-authentication/delete-authentication.service'; import { MESSAGE_PUBLISHER } from '@src/app.di-tokens'; import { MessageBrokerPublisher } from '@mobicoop/message-broker-module'; import { UsernameRepository } from './infrastructure/username.repository'; import { UsernameMapper } from './username.mapper'; import { AddUsernameGrpcController } from './interface/grpc-controllers/add-username.grpc.controller'; import { AddUsernameService } from './core/application/commands/add-username/add-username.service'; import { DeleteUsernameGrpcController } from './interface/grpc-controllers/delete-username.grpc.controller'; import { DeleteUsernameService } from './core/application/commands/delete-username/delete-username.service'; const grpcControllers = [ CreateAuthenticationGrpcController, DeleteAuthenticationGrpcController, AddUsernameGrpcController, DeleteUsernameGrpcController, ]; const commandHandlers: Provider[] = [ CreateAuthenticationService, DeleteAuthenticationService, AddUsernameService, DeleteUsernameService, ]; const mappers: Provider[] = [AuthenticationMapper, UsernameMapper]; const repositories: Provider[] = [ { provide: AUTHENTICATION_REPOSITORY, useClass: AuthenticationRepository, }, { provide: USERNAME_REPOSITORY, useClass: UsernameRepository, }, ]; const messageBrokers: Provider[] = [ { provide: MESSAGE_PUBLISHER, useClass: MessageBrokerPublisher, }, ]; const orms: Provider[] = [PrismaService]; @Module({ imports: [CqrsModule], controllers: [...grpcControllers], providers: [ ...commandHandlers, ...mappers, ...repositories, ...messageBrokers, ...orms, ], exports: [ PrismaService, AuthenticationMapper, AUTHENTICATION_REPOSITORY, USERNAME_REPOSITORY, ], }) export class AuthenticationModule {}