nestjs-smart-modules - v1.1.2
    Preparing search index...

    Function smartModule

    • Turns a module definition into a configurable module factory.

      The returned factory accepts the merged configuration of every smartConfigs class and every composed smartImports factory in the tree, and produces a NestJS DynamicModule. Configuration can be passed synchronously (a plain object) or asynchronously (an AsyncParams object with useFactory/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.

      Type Parameters

      Parameters

      • ...args: [...T[], SmartModuleOrFactory<[...T[]], [...TC[]], [...TI[]]>]

        Optional inline AnySmartConfig classes followed by a module definition object or a definition factory (imports, ...configs) => SmartModule.

      Returns InferSmartFactory<[...T[], ...TC[], ...TI[]]>

      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.

      Parameters

      Returns () => DynamicModule