All quizzesHard
Module Internals — Series 3
Preview — 3 of 10 questions
Both call sites pass what looks like identical configuration, yet two module instances appear. Why?
javascript
SharedModule.forRoot({ retries: 3, onError: (err) => logger.error(err) })
// imported from two different modules with the same literalABecause forRoot() deliberately creates a fresh instance per importer
BBecause the module was not marked @Global()
CBecause the token is derived from the module class plus a serialisation of the dynamic metadata, and a function value cannot be serialised into a stable, comparable form — two structurally "identical" literals produce different tokens, so the cache misses and the module is registered twice
DBecause object literals are compared by reference, so no two calls ever match
Why are modules discovered before their dependencies are read?
javascript
DependenciesScanner: scanForModules(...) → scanModulesForDependencies(...)ABecause every module must exist in the container before relationships are resolved — imports, exports and providers all reference modules and tokens that may be declared later in the traversal, so a single pass would hit references to modules not yet registered
BBecause the first pass validates decorators and the second compiles TypeScript metadata
CBecause controllers are registered in the first pass and providers in the second
DBecause the first pass runs synchronously and the second asynchronously
A provider in a module importing CoreModule injects LoggerService. How is it found?
javascript
@Module({ providers: [LoggerService], exports: [LoggerService] })
export class LoggerModule {}
@Module({ imports: [LoggerModule], exports: [LoggerModule] })
export class CoreModule {}ACoreModule is required to re-declare LoggerService in its own providers for this to work
BThe container flattens all exports into one global registry at startup
CThe token is resolved by scanning every module in the container until a match is found
DExporting a module rather than a token means "everything this module exports is also exported by me", so resolution follows the export chain: the importer looks in CoreModule's exports, finds LoggerModule listed, and continues into that module's own exports
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.