Reputation: 548
I currently have two modules:
Auth
which handles login and registrationUser
which handles all user crud operationsAuth
requires the User
module to register and validate users. So currently, Auth
imports the User
module:
@Module({
imports: [UserModule],
components: [JwtStrategy, GithubStrategy, TokenService, LoginService],
controllers: [AuthController],
})
However, as a result if I ever wanted to re-use these modules, I'd have to include both. Furthermore, if I moved the User
module, I'd have to update all the references to it within the Auth
module. Is there a better way to organise two dependent modules? Should they be combined?
Is there a better way to do this?
Upvotes: 0
Views: 160
Reputation: 187
If your UserModule
will be used everywhere, say in OrdersModules
, NotificationsModule
..., and you found yourself importing it and reimporting everywhere, then you should take a step to make this Module
a GlobalModule
, then it will be available everywhere in your project since it imported in RootModule
i.e ApplicationModule
Just annotate your Module by @Global
See also: Modules | Nest Documentations
Upvotes: 1