xInjection - v2.1.2
    Preparing search index...

    Type Alias ProviderFactoryToken<T>

    ProviderFactoryToken: ProviderOptions<T> & ProviderScopeOption & {
        inject?: ProviderIdentifier[];
        useFactory: (...providers: any[]) => T;
    }

    Type Parameters

    • T

    Type declaration

    • Optionalinject?: ProviderIdentifier[]

      Optional list of providers to be injected into the context of the Factory function.

      Note: The current module container context is available too.

      ProviderModule.create({
      id: 'FactoryProviderModule',
      providers: [
      DatabaseService,
      {
      provide: 'DATABASE_SECRET',
      useFactory: (dbService: DatabaseService) => {
      // Here you have access to the already resolved `DatabaseService` of the `FactoryProviderModule`.
      return dbService.getSecret();
      },
      inject: [DatabaseService]
      }
      ]
      });
    • useFactory: (...providers: any[]) => T

      Factory function that returns an instance of the provider to be injected.

      const connectionProvider = {
      provide: 'CONNECTION',
      useFactory: (optionsService: OptionsService, secondService: SecondService) => {
      const options = optionsService.get();

      return new DatabaseConnection(options);
      },
      // `inject` is optional.
      inject: [OptionsService, SecondService]
      };