nestjs / typeorm

TypeORM module for Nest framework (node.js) 🍇

Home Page:https://nestjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inject custom services in Subscribers

AhmadRaza786 opened this issue · comments

I have added subscriber for my entity

@EventSubscriber()
@Injectable()
export class SalesOrderSubscriber implements EntitySubscriberInterface<SalesOrderEntity> {
  constructor(
    private readonly userService: UserService,
    private readonly notificationService: NotificationService
  ) {}

  listenTo(): typeof SalesOrderEntity {
    return SalesOrderEntity;
  }

  async afterInsert({ entity }: InsertEvent<SalesOrderEntity>): Promise<void> {
    console.log(this.userService, this.notificationService) // both services are required.
  }
}

But this subscriber gets trigger if I remove the notificationService from the constructor. But I need both services here. What can be the reason for it?

Please search through some of our old issues on this (this has been discussed several times in the past).