Interface for extension bundles.

You may use this system to quickly register a set of services that belong together.

You can also use this to add 'feature toggles' for your application. E.g. only load some bundles in some specific configuration.

Example

class MyBundle implements BundleInterface<MyBundleConfig> {

constructor(public database: Database) {}

configure(overrides: Partial<MyBundleConfig>): void {
// See configure() below
}
}
interface BundleInterface<T> {
    configure(overrides): void;
}

Type Parameters

  • T extends object

    Refers to the type of bundle configuration. See BundleConfigType.

Methods

Methods

  • In this method, you can 'wire' the services that your bundle provides.

    Parameters

    • overrides: T

      Bundle configuration overrides.

    Returns void

    Example

    // Let's say that this bundle provides a `Database` and `DTO` class. 
    configure(overrides: Partial<MyBundleConfig>): void {

    // Merge bundle configuration with the given defaults and overrides
    const config = {...new MyBundleConfig(), ...overrides}

    // Get some container parameter (could also be passed via config)
    const db_uri = container.getParameter('db_uri');

    // Wire the services in this bundle
    container.transient(LoggerService, [config.logLevel]);
    container.singleton(Database, [db_uri, LoggerService]);
    container.singleton(SomeDTO, [Database]);

    // Register 'self'
    container.register(MyBundle, [Database, SomeDTO]);
    }

Generated using TypeDoc