Optional inline AnySmartConfig classes followed by a
module definition object or a definition factory
(imports, ...configs) => SmartModule.
A factory (config) => DynamicModule whose parameter type is
inferred from every config class and composed import in the definition.
class DatabaseConfig {
url: string
}
@Injectable()
class DatabaseService {
static smartModule = smartModule({
smartConfigs: [DatabaseConfig],
providers: [DatabaseService],
exports: [DatabaseService],
})
constructor(private readonly config: DatabaseConfig) {}
}
// in AppModule: imports: [DatabaseService.smartModule({ url: 'postgres://…' })]
Definition without smart configs or smart imports: the returned factory takes no configuration argument.
Turns a module definition into a configurable module factory.
The returned factory accepts the merged configuration of every
smartConfigsclass and every composedsmartImportsfactory in the tree, and produces a NestJS DynamicModule. Configuration can be passed synchronously (a plain object) or asynchronously (an AsyncParams object withuseFactory/inject/imports).Inline config classes may precede the definition when it is a factory function — their instantiated values are passed to the factory so the module definition can depend on resolved configuration.
Each factory call creates its own
DynamicModule(and therefore its own provider instances); the merged configuration is delivered identically to every branch of the tree.