Guest User

Untitled

a guest
Jan 10th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import { Module, OnModuleInit } from '@nestjs/common';
  2. import { AppController } from './app.controller';
  3. import { AppService } from './app.service';
  4. import { Article } from './article.entity';
  5. import { ModuleRef } from '@nestjs/core';
  6. import { TypeOrmModule } from '@nestjs/typeorm';
  7. import { CommandBus, CQRSModule } from '@nestjs/cqrs';
  8. import { CreateArticleHandler } from './commands/handlers/create-article.handler';
  9.  
  10. @Module({
  11. imports: [
  12. TypeOrmModule.forRoot({
  13. type: 'mysql',
  14. host: 'localhost',
  15. port: 33061,
  16. username: 'root',
  17. password: 'root',
  18. database: 'croute',
  19. entities: [__dirname + '/**/*.entity{.ts,.js}'],
  20. synchronize: true,
  21. }),
  22. TypeOrmModule.forFeature([Article]),
  23. CQRSModule,
  24. ],
  25. controllers: [AppController],
  26. providers: [AppService, CreateArticleHandler],
  27. })
  28. export class AppModule implements OnModuleInit {
  29. constructor(
  30. private readonly commandBus$: CommandBus,
  31. private readonly moduleRef: ModuleRef,
  32. ) {}
  33.  
  34. onModuleInit() {
  35. this.commandBus$.setModuleRef(this.moduleRef);
  36. this.commandBus$.register([CreateArticleHandler]);
  37. }
  38. }
Add Comment
Please, Sign In to add comment