[???]nestjs Cross modules dependency injection
import module
providers service
So if you want use some controllers(this controllers is in some module), this time need to import module. ????
===========
https://github.com/zelazna/NestAPI/tree/master/src
Impotant:
constructor don’t use new(). Use this.usersService.
src/auth/auth.service.ts
import { Component } from '@nestjs/common';
import { UsersService } from '../users';
@Component() ?? Injectable
export class AuthService {
constructor(
private readonly usersService: UsersService,
) { }
async validateUser(signedUser): Promise {
const { email, password } = signedUser;
const user = await this.usersService.findOneByEmail(email);
return await EncryptorService.validate(password, user.password);
}
Impotant:
exports need UsersService
src/users/users.module.ts
import { UsersService } from './users.service';
@Module({
controllers: [UsersController],
components: [UsersService],
imports: [TypeOrmModule.forFeature([User])],
exports: [UsersService],
})