InterviewBuddy
All interview questions

How do modules share providers?

Intermediate

Answer

A module lists a provider in providers, exports it, and another module imports that module. Nest then resolves the dependency through its module graph.

Explanation

Simply declaring the same provider in several modules can create separate instances or confusing ownership. Define clear module boundaries.

Example

@Module({providers:[UsersService], exports:[UsersService]})