#module dependencies

5 messages · Page 1 of 1 (latest)

vivid epoch
#

I'm relatively new to nestjs, but I've read the docs and tried to work through the error I'm seeing. I think I must be misunderstanding something, though.

The error I'm getting is that UserRepository cannot resolve the PrismaService dependency.

app.module.ts

@Module({
  imports: [UserModule],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

prisma.module.ts

@Module({
  providers: [PrismaService],
  exports: [PrismaService],
})
export class PrismaModule {}

user.module.ts

@Module({
  imports: [PrismaModule],
  controllers: [UserController],
  providers: [
    { provide: IUserRepository, useClass: UserRepository },
    { provide: IUserService, useClass: UserService },
  ],
})
export class UserModule {}

user.repository.ts

@Injectable()
export class UserRepository implements IUserRepository {
  
  constructor(@Inject() private prismaClient: PrismaService) {}
}
iron spade
#

what if you drop that @Inject()?

#

as you're injecting a class-based providers, the @Inject() isn't needed

vivid epoch
#

aha yes, that did it!

#

thanks!