Having been using nestjs for a while, I have found it to be incredibly useful, especially as projects become larger and more complex.
However, I am currently facing an issue with dependency injection. I have always used it between modules of the same type (REST modules).
I followed the process outlined on the website, where I exported the desired service from this module:
@Module({
imports: [TypeOrmModule.forFeature([Bs]), forwardRef(() => WineModule)],
controllers: [BsController],
providers: [BsService],
exports: [BsService],
})
export class BsModule {}
and then imported it into another module:
@Module({
imports: [BsModule],
providers: [WebsocketGateway, WebsocketService],
exports: [WebsocketGateway],
})
export class WebsocketModule {}
Thanks to a previous post, I learned that I need to export the service but import the module. I have used this approach for several modules without any issues.
However, when I try to import something into a gateway module (used for socket.io), I am unable to compile due to a circular dependency error.
Usually, with other modules, I have been able to solve this issue using forwardRef. But with the gateway module, even when employing this strategy, it appears to not recognize the import and throws an error stating that it cannot find the module or service in the constructor.
I have searched for information on this topic, wondering if nestjs restricts the import and dependency injection between different types of services (rest to gateway or vice versa), but I have not found anything helpful.
Apologies for any typos, as I am trying to improve my English!
Thank you,
D.