I encountered an issue with a service I'm trying to import in CQRS during runtime - specifically, when using the service method.
The service is declared in the constructor and called in the execute method as shown below:
@CommandHandler(UpdateSensorsProductsCommand)
export class UpdateSensorsProductsCommandHandler implements ICommandHandler<UpdateSensorsProductsCommand>
{
constructor(
private eventBus: EventBus,
private sensorProductListService: SensorProductsListService,
) {}
async execute(
command: UpdateSensorsProductsCommand,
) {
// Error message received: TypeError: Cannot read property 'getAllSensorsProducts' of undefined
this.sensorProductListService.getAllSensorsProducts()
}
}
In addition, I have imported the sensorProductListService module in my CQRS module named SystemCqrsModule
:
@Module({
imports: [
CqrsModule,
SensorProductsListModule,
],
...
exports: [CqrsModule],
})
export class SystemCqrsModule {}
Furthermore, I export sensorProductListService from the sensorProductListModule:
This is the sensorProductListModule:
@Module({
providers: [SensorProductsListService, UnitConvert],
exports: [SensorProductsListService],
})
export class SensorProductsListModule {}
Despite these configurations, the following error persists:
TypeError: Cannot read property 'getAllSensorsProducts' of undefined
What could be causing this error?