refactor modules
This commit is contained in:
parent
aa06b8c54c
commit
74a855c1b9
|
@ -53,7 +53,5 @@ import { HealthModule } from '@modules/health/health.module';
|
||||||
HealthModule,
|
HealthModule,
|
||||||
AdModule,
|
AdModule,
|
||||||
],
|
],
|
||||||
controllers: [],
|
|
||||||
providers: [],
|
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Module } from '@nestjs/common';
|
import { Module, Provider } from '@nestjs/common';
|
||||||
import { CreateAdGrpcController } from './interface/grpc-controllers/create-ad.grpc.controller';
|
import { CreateAdGrpcController } from './interface/grpc-controllers/create-ad.grpc.controller';
|
||||||
import { CqrsModule } from '@nestjs/cqrs';
|
import { CqrsModule } from '@nestjs/cqrs';
|
||||||
import {
|
import {
|
||||||
|
@ -25,40 +25,66 @@ import { FindAdByIdQueryHandler } from './core/queries/find-ad-by-id/find-ad-by-
|
||||||
import { PublishMessageWhenAdIsCreatedDomainEventHandler } from './core/event-handlers/publish-message-when-ad-is-created.domain-event-handler';
|
import { PublishMessageWhenAdIsCreatedDomainEventHandler } from './core/event-handlers/publish-message-when-ad-is-created.domain-event-handler';
|
||||||
import { PublishLogMessageWhenAdIsCreatedDomainEventHandler } from './core/event-handlers/publish-log-message-when-ad-is-created.domain-event-handler';
|
import { PublishLogMessageWhenAdIsCreatedDomainEventHandler } from './core/event-handlers/publish-log-message-when-ad-is-created.domain-event-handler';
|
||||||
|
|
||||||
|
const grpcControllers = [CreateAdGrpcController, FindAdByIdGrpcController];
|
||||||
|
|
||||||
|
const eventHandlers: Provider[] = [
|
||||||
|
PublishMessageWhenAdIsCreatedDomainEventHandler,
|
||||||
|
PublishLogMessageWhenAdIsCreatedDomainEventHandler,
|
||||||
|
];
|
||||||
|
|
||||||
|
const commandHandlers: Provider[] = [CreateAdService];
|
||||||
|
|
||||||
|
const queryHandlers: Provider[] = [FindAdByIdQueryHandler];
|
||||||
|
|
||||||
|
const mappers: Provider[] = [AdMapper];
|
||||||
|
|
||||||
|
const repositories: Provider[] = [
|
||||||
|
{
|
||||||
|
provide: AD_REPOSITORY,
|
||||||
|
useClass: AdRepository,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const messageBrokers: Provider[] = [
|
||||||
|
{
|
||||||
|
provide: MESSAGE_BROKER_PUBLISHER,
|
||||||
|
useClass: MessageBrokerPublisher,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: MESSAGE_PUBLISHER,
|
||||||
|
useClass: MessagePublisher,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const orms: Provider[] = [PrismaService];
|
||||||
|
|
||||||
|
const utilities: Provider[] = [
|
||||||
|
{
|
||||||
|
provide: PARAMS_PROVIDER,
|
||||||
|
useClass: DefaultParamsProvider,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: TIMEZONE_FINDER,
|
||||||
|
useClass: TimezoneFinder,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: TIME_CONVERTER,
|
||||||
|
useClass: TimeConverter,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [CqrsModule],
|
imports: [CqrsModule],
|
||||||
controllers: [CreateAdGrpcController, FindAdByIdGrpcController],
|
controllers: [...grpcControllers],
|
||||||
providers: [
|
providers: [
|
||||||
CreateAdService,
|
...eventHandlers,
|
||||||
FindAdByIdQueryHandler,
|
...commandHandlers,
|
||||||
PublishMessageWhenAdIsCreatedDomainEventHandler,
|
...queryHandlers,
|
||||||
PublishLogMessageWhenAdIsCreatedDomainEventHandler,
|
...mappers,
|
||||||
PrismaService,
|
...repositories,
|
||||||
AdMapper,
|
...messageBrokers,
|
||||||
{
|
...orms,
|
||||||
provide: AD_REPOSITORY,
|
...utilities,
|
||||||
useClass: AdRepository,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: PARAMS_PROVIDER,
|
|
||||||
useClass: DefaultParamsProvider,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: MESSAGE_BROKER_PUBLISHER,
|
|
||||||
useClass: MessageBrokerPublisher,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: MESSAGE_PUBLISHER,
|
|
||||||
useClass: MessagePublisher,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: TIMEZONE_FINDER,
|
|
||||||
useClass: TimezoneFinder,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: TIME_CONVERTER,
|
|
||||||
useClass: TimeConverter,
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
PrismaService,
|
PrismaService,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Module } from '@nestjs/common';
|
import { Module, Provider } from '@nestjs/common';
|
||||||
import { HealthHttpController } from './interface/http-controllers/health.http.controller';
|
import { HealthHttpController } from './interface/http-controllers/health.http.controller';
|
||||||
import { TerminusModule } from '@nestjs/terminus';
|
import { TerminusModule } from '@nestjs/terminus';
|
||||||
import { MESSAGE_BROKER_PUBLISHER, MESSAGE_PUBLISHER } from 'src/app.constants';
|
import { MESSAGE_BROKER_PUBLISHER, MESSAGE_PUBLISHER } from 'src/app.constants';
|
||||||
|
@ -10,23 +10,33 @@ import { AD_REPOSITORY } from './health.di-tokens';
|
||||||
import { HealthGrpcController } from './interface/grpc-controllers/health.grpc.controller';
|
import { HealthGrpcController } from './interface/grpc-controllers/health.grpc.controller';
|
||||||
import { AdModule } from '@modules/ad/ad.module';
|
import { AdModule } from '@modules/ad/ad.module';
|
||||||
|
|
||||||
|
const grpcControllers = [HealthGrpcController];
|
||||||
|
|
||||||
|
const httpControllers = [HealthHttpController];
|
||||||
|
|
||||||
|
const useCases: Provider[] = [RepositoriesHealthIndicatorUseCase];
|
||||||
|
|
||||||
|
const repositories: Provider[] = [
|
||||||
|
{
|
||||||
|
provide: AD_REPOSITORY,
|
||||||
|
useClass: AdRepository,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const messageBrokers: Provider[] = [
|
||||||
|
{
|
||||||
|
provide: MESSAGE_BROKER_PUBLISHER,
|
||||||
|
useClass: MessageBrokerPublisher,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: MESSAGE_PUBLISHER,
|
||||||
|
useClass: MessagePublisher,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [TerminusModule, AdModule],
|
imports: [TerminusModule, AdModule],
|
||||||
controllers: [HealthGrpcController, HealthHttpController],
|
controllers: [...grpcControllers, ...httpControllers],
|
||||||
providers: [
|
providers: [...useCases, ...repositories, ...messageBrokers],
|
||||||
RepositoriesHealthIndicatorUseCase,
|
|
||||||
{
|
|
||||||
provide: AD_REPOSITORY,
|
|
||||||
useClass: AdRepository,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: MESSAGE_BROKER_PUBLISHER,
|
|
||||||
useClass: MessageBrokerPublisher,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: MESSAGE_PUBLISHER,
|
|
||||||
useClass: MessagePublisher,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
})
|
||||||
export class HealthModule {}
|
export class HealthModule {}
|
||||||
|
|
Loading…
Reference in New Issue