I have a UserRepository
which handles creating/authenticating users infront of the database. I want to perform hashing & validation for the user's password, so I created a seperate service for that purpose, trying to follow single repsonsibility principle, which is declared like this:
@Injectable()
export default class HashService
And I import it in my module:
@Module({
imports: [TypeOrmModule.forFeature([UserRepository])],
controllers: [AuthController],
providers: [AuthService, HashService],
})
export class AuthModule {}
I wish to inject it into UserRepository
, I tried passing in it as a constructor parameter but it didn't work because it's base class already accepts 2 parameters there, so I tried injecting my service after them like so:
@EntityRepository(User)
export default class UserRepository extends Repository<User> {
constructor(
entityManager: EntityManager,
entityMetadata: EntityMetadata,
@Inject() private readonly hashService: HashService,
) {
super();
}
// Logic...
}
But hashService
was undefined, I also tried without the @Inject()
decorator.
What would be the best way to inject HashService
into my repository? Do I have to create a new instance of it?