#Common EventBus between modules
15 messages · Page 1 of 1 (latest)
The handler is most likely not in any module's providers array and thus not instantiated, otherwise it should work.
so you are telling that if I put handlers to providers array it should work right?
Yes
which is already what I did, then there is another problem
I will when I get back to home
thank you for your attention btw
Here is my Event try to handle:
export class DiscordBanUserEvent extends BaseDiscordEvent {
constructor(props: EventProps<DiscordBanUserEvent>, correlationId: string) {
super(correlationId);
this.userId = props.userId;
this.duration = props.duration;
}
userId?: BasePropType<string>;
duration?: BasePropType<string | DurationEnums>;
}
Here is my Event Handler:
@EventsHandler(DiscordBanUserEvent)
export class BanUserEventHandler implements IEventHandler<DiscordBanUserEvent> {
private readonly logger = new Logger(BanUserEventHandler.name);
constructor(
private readonly prismaService: PrismaService,
private readonly configService: ConfigService,
private readonly responseAdapter: DiscordResponseAdapter,
) {}
async handle(event: DiscordBanUserEvent) {
...
}
Here is the command handler which is working and publishing the DiscordBanUserEvent from eventbus.
@CommandHandler(DiscordRequestCommand)
export class DiscordRequestCommandHandler implements ICommandHandler<DiscordRequestCommand> {
private readonly logger = new Logger(DiscordRequestCommandHandler.name);
constructor(private readonly openaiAdapter: OpenAiAdapter, private eventBus: EventBus) {}
async execute(command: DiscordRequestCommand): Promise<any> {
...
const event = await this.apiAdapter.getCorrespondingDiscordEvent(command.commandInput, command.correlationId);
this.eventBus.publish(event);
}
}
When I debug I can see this.eventBus.publish() called with proper event.
Here is SlashRequestModule:
@Module({
imports: [CqrsModule],
providers: [DiscordRequestCommandHandler, SlashRequestController],
})
export class SlashRequestModule {}
Here is the BanUserModule:
@Module({
providers: [BanUserEventHandler, ...controllers],
imports: [InfrastructureModule, CqrsModule],
})
export class BanUserModule {}
there is no error at all
but BanUserEventHandler is not executing
okay I understand the problem
finally
lmao