Bird
0
0

In a NestJS app using TypeORM, how can you ensure repositories are available in lazy-loaded modules?

hard📝 Application Q9 of 15
NestJS - Database with TypeORM
In a NestJS app using TypeORM, how can you ensure repositories are available in lazy-loaded modules?
ARepositories are automatically available without imports
BDeclare repositories as global providers manually
CUse a single forRoot() call in the root module only
DImport TypeOrmModule.forFeature() with entities in each lazy-loaded module
Step-by-Step Solution
Solution:
  1. Step 1: Understand lazy-loaded modules isolation

    Lazy-loaded modules have their own scope and need explicit imports.
  2. Step 2: Import forFeature() in each module

    Repositories must be registered via TypeOrmModule.forFeature() in each module needing them.
  3. Final Answer:

    Import TypeOrmModule.forFeature() with entities in each lazy-loaded module -> Option D
  4. Quick Check:

    forFeature import per module = A [OK]
Quick Trick: Add forFeature imports in every module needing repositories [OK]
Common Mistakes:
  • Assuming repositories are global automatically
  • Trying to declare repositories as global providers
  • Relying only on root module forRoot()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes