Closed zelazna closed 6 years ago
Hi @zelazna,
You defined AuthService
and JwtStrategy
twice. They're needless in the CatsModule
, let's remove them https://github.com/zelazna/Nest.js-Test/blob/master/src/cats/cats.module.ts
Thanks @kamilmysliwiec, it works !! Is it an expected behaviour ?
Definitely. Why did you define them twice? 🙂
i messed up :), i'm talking about the error dropped, wich was very confusing for me ( no offense, Nest.js is really awesome, keep going ! )
thanks! 😃
I have a service and an event-gateway. They use each other with depency injection pattern. I had made according to examples forwardRef method.
Problem: each of them are created twice, they are not singletones.
events.module.ts
import {forwardRef, Module} from '@nestjs/common';
import {EventsGateway} from './events.gateway';
import {WidgetModule} from '../widget/widget.module';
import {WidgetService} from '../widget/widget.service';`
@Module({
providers: [EventsGateway, WidgetService],
imports: [forwardRef(() => WidgetModule)],
exports: [EventsGateway],
})
export class EventsModule {
}
widget.module.ts
import {WidgetController} from './widget.controller';
import {UserService} from './user.service';
import {MiddlewaresConsumer} from '@nestjs/common/interfaces/middlewares';
import {LoggerMiddleware} from '../common/middlewares/logger.middleware';
import {BrainService} from './brain.service';
import {WidgetService} from './widget.service';
import {EventsModule} from '../events/events.module';
import {EventsGateway} from '../events/events.gateway';
@Module({
controllers: [WidgetController],
providers: [UserService, BrainService, WidgetService, EventsGateway],
exports: [WidgetService, UserService, BrainService],
imports: [forwardRef(() => EventsModule)],
})
export class WidgetModule implements NestModule {
configure(consumer: MiddlewaresConsumer) {
consumer.apply([LoggerMiddleware]).forRoutes(WidgetController);
}
}
widget.service.ts
@Injectable()
export class WidgetService {
constructor(private readonly userService: UserService,
private readonly brainSerivce: BrainService,
@Inject(forwardRef(() => EventsGateway))
private readonly eventsGateway: EventsGateway) {
console.log('WidgetService created');
}
...
}
events.gateway.ts
@WebSocketGateway(8080)
export class EventsGateway {
@WebSocketServer() server;
constructor(
@Inject(forwardRef(() => WidgetService))
private readonly widgetService: WidgetService) {
console.log('EventsGateway created');
}
...
}
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
I'm submitting a...
Current behavior
I've a weird issue, Nest.js generate an error if i imported the services dependencies in the module.ts. I try to mix 2 services together, the UsersService and the AuthService
The AuthService dropping the error :
The AuthModule :
The UsersModule:
At last the generated error :
I already tried to export import the TypeOrmModule by it's not currently working, any idea ? thanks by advance !
Expected behavior
The dependency is injected properly in the service
Minimal reproduction of the problem with instructions
here's the github
Environment