title: Dynamic Module dependency injection
body: <p>I am trying to do something fancy: a DynamicModule that chooses a Controller/Providers depending on a provider. The provider reads a config in a DB at onModuleInit, so there is no way to hard-code its values.</p>
  <p>It is similar to this issue: <a href="https://github.com/nestjs/nest/issues/601" rel="nofollow noreferrer">https://github.com/nestjs/nest/issues/601</a> which was never answered...</p>
  <p>I have tried a few approaches and the closest I have got is this:</p>
  <pre class="lang-js prettyprint-override"><code>export class FancyModule implements DynamicModule {
    public module: Type&lt;FancyModule&gt;;
    public controllers: Type&lt;unknown&gt;[];
    public providers: Provider&lt;unknown&gt;[];
    constructor (
      @Inject(StartupConfigService) private readonly startup: StartupConfigService,
    ) {
      this.module = FancyModule;
      if (startup.featureFlagEnabled) {
        this.controllers = [ FancyFeatureController ];
        this.providers = [ FancyFeatureService ];
      } else {
        this.controllers = [ ErrorController ];
        this.providers = [];
      }
    }
  }
  </code></pre>
  <p>Second approach:</p>
  <p>app.module.ts</p>
  <pre class="lang-js prettyprint-override"><code>@Module({
    imports: [
      StartupConfigModule.register(startupConfigOption),
      FancyModule.registerAsync({
        imports: [StartupConfigModule],
        useFactory: function (startupConfigService: StartupConfigService) {
             return startupConfigService.config
        },
        inject: [StartupConfigService],
     }),
   ],
  })
  </code></pre>
  <p>fancy.module.ts</p>
  <pre class="lang-js prettyprint-override"><code>export class FancyModule {
    static registerAsync (config: IAppConfig): DynamicModule {
      if (config.featureFlagEnabled) {
        return {
          module: FancyModule,
          controllers: [ FancyFeatureController ],
          providers: [ FancyFeatureService ],
        };
      } else {
        return {
          module: FancyModule,
          controllers: [ ],
          providers: [ ],
        };
      }
    }
  }
  </code></pre>
  <p>This injects as expected but the controllers and providers are never spun up. Is the meta-data evaluated before the constructor? Is that a bug?</p>