xInjection - v2.1.2
    Preparing search index...

    Class IProviderModuleAbstract

    Implemented by

    Index

    Constructors

    Properties

    definition: ModuleDefinition<true>

    The ModuleDefinition of this Module.

    Note: You shouldn't manually modify the ModuleDefinition! Interact via the update methods instead.

    id: ModuleIdentifier

    The identifier of this Module.

    isDisposed: boolean

    It'll be true after the dispose method has been invoked.

    middlewares: IMiddlewaresManager

    Methods

    • It first invokes the reset method and then permanentely destroys the module's container.

      Note: If other modules have imported this module, they'll not be able anymore to resolve dependencies from it which will cause errors to be thrown! Make sure to use dispose carefully as it is an irreversible action.

      Returns Promise<void>

    • Can be used to retrieve many providers from the module container at once.

      Type Parameters

      Parameters

      Returns ProviderModuleGetManyReturn<D>

      Tuple containing the providers.

      // When ProviderTokens are supplied, TS auto-inference works as expected.
      // `car` will infer the `Car` type, `engine` the `Engine` type and `dashboard` the `Dashboard` type.
      const [car, engine, dashboard, wheels] = Module.getMany(
      Car,
      Engine,
      { provider: Dashboard, isOptional: true },
      { provider: Wheel, asList: true },
      );

      // When auto-inference is not possible, you can manually cast the types.
      const [configService, userService] = Module.getMany('CONFIG_SERVICE', UserService) as [ConfigService, UserService];
      // Now the `configService` is of type `ConfigService` and the `userService` is of type `UserService`.
    • Can be used to completely reset a module.

      It means that all bound providers will be removed from the container and all definitions cleared, leaving it as a pristine module ready to be updated with new definitions.

      Note: This is not the same as the dispose method!

      Returns Promise<void>

    • Can be used when you don't want to initialize a ProviderModule eagerly as each ProviderModule has its own container initialized as soon as you do ProviderModule.create({...}).

      The ProviderModuleBlueprint allows you to just define a blueprint of a ProviderModule, you can then decide to either instantiate it or import as it is into different modules (or blueprints).

      Note: As soon as you import a blueprint into a module, it'll be automatically transformed into a IProviderModule instance! Also keep in mind that editing the blueprint after it has been consumed by a module will not propagate the changes to the consumer module!

      [WARNING]: When you import the same blueprint into different modules, each module will create a new module instance based on that specific blueprint, this may not seem obvious at first, but it happens because a blueprint is just that, a template defining the options which will be used to build a module. This means that if a blueprint exports a singleton provider, when imported into two separate modules, each module will have its own instance of that specific singleton provider! You should also keep in mind that once a blueprint has been encapsulated into a module, it can't be removed anymore as you can do with the modules!

      Why should you use a ProviderModuleBlueprint?

      • To define module configurations upfront without incurring the cost of immediate initialization.
      • To reuse module definitions across different parts of your application while maintaining isolated instances.
      • To compose modules flexibly, allowing you to adjust module dependencies dynamically before instantiation.

      You can always edit a property of the blueprint after creating it by doing:

      const GarageModuleBlueprint = ProviderModule.blueprint({ id: 'GarageModuleBlueprint' });

      // Later in your code

      GarageModuleBlueprint.updateDefinition({
      imports: [...GarageModuleBlueprint.imports, PorscheModule, FerrariModuleBlueprint]
      });

      // ...

      const GarageModule = ProviderModule.create(GarageModuleBlueprint);

      // or

      ExistingModule.update.addImport(GarageModuleBlueprint);

      Parameters

      Returns ProviderModuleBlueprint