There is a UserService
that is required by the UserModule
and then added to the exports
.
import {Module} from '@nestjs/common'
import {TypeOrmModule} from '@nestjs/typeorm'
import {User} from './user.entity'
import {UserService} from './user.service'
@Module({
imports: [TypeOrmModule.forFeature([User])],
components: [UserService],
controllers: [],
exports: [UserService]
})
export class UserModule{}
Next, an AuthModule
needs to utilize the UserService
, which is as follows:
import * as passport from 'passport'
import * as PassportAzureAD from 'passport-azure-ad'
import * as session from 'express-session'
import {
Module,
NestModule,
MiddlewaresConsumer,
RequestMethod,
} from '@nestjs/common'
import {Logger} from '@nestjs/common'
import {UserModule} from '../user/user.module'
@Module({
imports: [UserModule],
components: [],
controllers: []
})
export class AuthModule implements NestModule{
public configure(consumer: MiddlewaresConsumer){
// SNIP
// How to incorporate `UserService` here
}
}
In what way can the UserService
be utilized in this scenario? The documentation explains:
Now each module which would import the CatsModule (we need to put CatsModule into the imports array) has access to the CatsService and will share the same instance with all of the modules which are importing this module too.
Despite this explanation, there isn't a concrete example provided on how to achieve it practically.