Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Module, OnModuleInit } from '@nestjs/common';
- import { AppController } from './app.controller';
- import { AppService } from './app.service';
- import { Article } from './article.entity';
- import { ModuleRef } from '@nestjs/core';
- import { TypeOrmModule } from '@nestjs/typeorm';
- import { CommandBus, CQRSModule } from '@nestjs/cqrs';
- import { CreateArticleHandler } from './commands/handlers/create-article.handler';
- @Module({
- imports: [
- TypeOrmModule.forRoot({
- type: 'mysql',
- host: 'localhost',
- port: 33061,
- username: 'root',
- password: 'root',
- database: 'croute',
- entities: [__dirname + '/**/*.entity{.ts,.js}'],
- synchronize: true,
- }),
- TypeOrmModule.forFeature([Article]),
- CQRSModule,
- ],
- controllers: [AppController],
- providers: [AppService, CreateArticleHandler],
- })
- export class AppModule implements OnModuleInit {
- constructor(
- private readonly commandBus$: CommandBus,
- private readonly moduleRef: ModuleRef,
- ) {}
- onModuleInit() {
- this.commandBus$.setModuleRef(this.moduleRef);
- this.commandBus$.register([CreateArticleHandler]);
- }
- }
Add Comment
Please, Sign In to add comment