All quizzesMedium
Modules & Sharing — Series 3
Preview — 3 of 10 questions
What is this module for?
javascript
@Module({
imports: [LoggerModule, ConfigModule, MetricsModule],
exports: [LoggerModule, ConfigModule, MetricsModule],
})
export class InfrastructureModule {}ANothing useful — a module with no providers or controllers is ignored by the scanner
BIt merges the three modules into one instance, so their providers share state
CIt makes the three modules global, which is what re-exporting achieves
DIt is an aggregator: feature modules import one module instead of three, and the infrastructure set can change in one place without touching every consumer
Why is STORAGE_OPTIONS absent from exports?
javascript
@Module({})
export class StorageModule {
static forRoot(options: StorageOptions): DynamicModule {
return {
module: StorageModule,
providers: [
{ provide: STORAGE_OPTIONS, useValue: options },
StorageService,
],
exports: [StorageService],
};
}
}ABecause it is an internal detail: StorageService injects it, but consumers should depend on the service's API rather than on how it was configured — exporting it would make the options object part of the module's public contract
BBecause useValue providers cannot be exported
CBecause tokens created inside a static method are automatically global
DBecause a dynamic module may export at most one token
What does exporting only BillingService buy?
javascript
@Module({
providers: [BillingService, InvoiceRepository, TaxCalculator, PdfRenderer],
exports: [BillingService],
})
export class BillingModule {}AA smaller compiled output, since unexported providers are tree-shaken away
BFaster startup, because unexported providers are instantiated lazily
COne published entry point: consumers cannot reach TaxCalculator or PdfRenderer, so those can be renamed, merged or replaced without breaking anyone — and the module's contract stays small enough to reason about
DAutomatic transaction handling around every exported method
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.