Inject custom services in Subscribers
AhmadRaza786 opened this issue · comments
Ahmad Raza commented
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?
Kamil Mysliwiec commented
Please search through some of our old issues on this (this has been discussed several times in the past).