This repository has been archived by the owner on Nov 7, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
comment.module.ts
56 lines (52 loc) 路 1.63 KB
/
comment.module.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { Module, OnModuleInit } from '@nestjs/common';
import { CorporationModule } from '../corporation/corporation.module';
import { AllianceModule } from '../alliance/alliance.module';
import { PostModule } from '../post/post.module';
import { CommentService } from './comment.service';
import { CharacterModule } from '../character/character.module';
import { CommentController } from './comment.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { CommentRepository } from './comment.repository';
import { CommandBus, CQRSModule, EventBus } from '@nestjs/cqrs';
import { ModuleRef } from '@nestjs/core';
import { eventHandlers } from './events/handlers';
import { commandHandlers } from './commands/handlers';
import { WebsocketModule } from '../websocket/websocket.module';
@Module({
imports: [
CQRSModule,
TypeOrmModule.forFeature([CommentRepository]),
CorporationModule,
AllianceModule,
CharacterModule,
PostModule,
WebsocketModule,
],
controllers: [
CommentController,
],
providers: [
CommentService,
...commandHandlers,
...eventHandlers,
],
exports: [
CommentService,
],
})
export class CommentModule implements OnModuleInit {
constructor(
private readonly moduleRef: ModuleRef,
private readonly command$: CommandBus,
private readonly event$: EventBus,
) {
// FIXME: Nasty hack, for some reason onModuleInit isn't executed
this.onModuleInit();
}
onModuleInit() {
this.command$.setModuleRef(this.moduleRef);
this.event$.setModuleRef(this.moduleRef);
this.event$.register(eventHandlers);
this.command$.register(commandHandlers);
}
}