Type alias ModuleDeclaration<T>

ModuleDeclaration<T>: {
    afterBinding?: ((container: Container) => void);
    beforeBinding?: ((container: Container) => void);
    exports?: { [ K in keyof GetModuleProps<T>]?: Token<GetModuleProps<T>[K]> };
    factory: ((container: Container) => T);
    imports?: ReadonlyArray<ModuleBindingEntry>;
    token: Token<T>;
}

Description how to bind the module in declarative way.

Example

const LOGGER_MODULE: ModuleDeclaration<LoggerModule> = {
token: LOGGER_MODULE_TOKEN,
factory: (container) => {
const transport = container.resolve(TRANSPORT_TOKEN).open();
return {
logger: { log: (message) => transport.write(message) },
destroy: () => transport.close(),
}
},
exports: {
logger: LOGGER_TOKEN,
},
};

Type Parameters

Type declaration

  • Optional afterBinding?: ((container: Container) => void)
      • (container: Container): void
      • Callback could be used to export complex dependencies from the module. It is called after binding the module.

        Parameters

        Returns void

  • Optional beforeBinding?: ((container: Container) => void)
      • (container: Container): void
      • Callback could be used to prepare an environment. It is called before binding the module.

        Parameters

        Returns void

  • Optional exports?: { [ K in keyof GetModuleProps<T>]?: Token<GetModuleProps<T>[K]> }

    Dictionary of module properties which are bound to tokens.

  • factory: ((container: Container) => T)
      • (container: Container): T
      • Factory of the module

        Parameters

        Returns T

  • Optional imports?: ReadonlyArray<ModuleBindingEntry>

    Modules for binding

  • token: Token<T>

    Token for the module

Generated using TypeDoc