Page Contents

Home > @loopback/boot > BootMixin

BootMixin() function

Mixin for @loopback/boot. This Mixin provides the following: - Implements the Bootable Interface as follows. - Add a projectRoot property to the Class - Adds an optional bootOptions property to the Class that can be used to store the Booter conventions. - Adds the BootComponent to the Class (which binds the Bootstrapper and default Booters) - Provides the boot() convenience method to call Bootstrapper.boot() - Provides the booter() convenience method to bind a Booter(s) to the Application - Override component() to call mountComponentBooters - Adds mountComponentBooters which binds Booters to the application from component.booters[]

Signature:

export declare function BootMixin<T extends MixinTarget<Application>>(superClass: T): {
    new (...args: any[]): {
        projectRoot: string;
        bootOptions?: BootOptions | undefined;
        booted: boolean;
        start(): Promise<void>;
        boot(): Promise<void>;
        booters(...booterCls: Constructor<Booter>[]): Binding[];
        applicationBooter(subApp: Application & Bootable, filter?: BindingFilter | undefined): Binding<Booter>;
        component<C extends Component = Component>(componentCtor: Constructor<C>, nameOrOptions?: string | BindingFromClassOptions | undefined): Binding<C>;
        mountComponentBooters(componentInstanceOrClass: Constructor<unknown> | InstanceWithBooters): void;
        readonly options: loopbackContext.ApplicationConfig;
        readonly state: string;
        controller: <T_1>(controllerCtor: Constructor<T_1>, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding<T_1>;
        server: <T_2 extends loopbackContext.Server>(ctor: Constructor<T_2>, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding<T_2>;
        servers: <T_3 extends loopbackContext.Server>(ctors: Constructor<T_3>[]) => Binding<any>[];
        getServer: <T_4 extends loopbackContext.Server>(target: string | Constructor<T_4>) => Promise<T_4>;
        onStart: (fn: () => void | PromiseLike<void>) => Binding<loopbackContext.LifeCycleObserver>;
        stop: () => Promise<void>;
        onStop: (fn: () => void | PromiseLike<void>) => Binding<loopbackContext.LifeCycleObserver>;
        setMetadata: (metadata: loopbackContext.ApplicationMetadata) => void;
        lifeCycleObserver: <T_5 extends loopbackContext.LifeCycleObserver>(ctor: Constructor<T_5>, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding<T_5>;
        service: <S>(cls: loopbackContext.ServiceOrProviderClass<S>, nameOrOptions?: string | loopbackContext.ServiceOptions | undefined) => Binding<S>;
        interceptor: (interceptor: loopbackContext.Interceptor | Constructor<loopbackContext.Provider<loopbackContext.Interceptor>>, nameOrOptions?: string | loopbackContext.InterceptorBindingOptions | undefined) => Binding<loopbackContext.Interceptor>;
        readonly name: string;
        readonly subscriptionManager: loopbackContext.ContextSubscriptionManager;
        readonly parent: Context | undefined;
        emitEvent: <T_6 extends loopbackContext.ContextEvent>(type: string, event: T_6) => void;
        emitError: (err: unknown) => void;
        bind: <ValueType = any>(key: loopbackContext.BindingAddress<ValueType>) => Binding<ValueType>;
        add: (binding: Binding<unknown>) => Application;
        configure: <ConfigValueType = any>(key?: string | loopbackContext.BindingKey<unknown> | undefined) => Binding<ConfigValueType>;
        getConfigAsValueOrPromise: <ConfigValueType_1>(key: loopbackContext.BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: loopbackContext.ResolutionOptions | undefined) => loopbackContext.ValueOrPromise<ConfigValueType_1 | undefined>;
        getConfig: <ConfigValueType_2>(key: loopbackContext.BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: loopbackContext.ResolutionOptions | undefined) => Promise<ConfigValueType_2 | undefined>;
        getConfigSync: <ConfigValueType_3>(key: loopbackContext.BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: loopbackContext.ResolutionOptions | undefined) => ConfigValueType_3 | undefined;
        unbind: (key: loopbackContext.BindingAddress<unknown>) => boolean;
        subscribe: (observer: loopbackContext.ContextEventObserver) => loopbackContext.Subscription;
        unsubscribe: (observer: loopbackContext.ContextEventObserver) => boolean;
        close: () => void;
        isSubscribed: (observer: loopbackContext.ContextObserver) => boolean;
        createView: <T_7 = unknown>(filter: BindingFilter, comparator?: loopbackContext.BindingComparator | undefined) => loopbackContext.ContextView<T_7>;
        contains: (key: loopbackContext.BindingAddress<unknown>) => boolean;
        isBound: (key: loopbackContext.BindingAddress<unknown>) => boolean;
        getOwnerContext: (key: loopbackContext.BindingAddress<unknown>) => Context | undefined;
        find: <ValueType_1 = any>(pattern?: string | RegExp | BindingFilter | undefined) => Readonly<Binding<ValueType_1>>[];
        findByTag: <ValueType_2 = any>(tagFilter: string | RegExp | Record<string, any>) => Readonly<Binding<ValueType_2>>[];
        get: {
            <ValueType_3>(keyWithPath: loopbackContext.BindingAddress<ValueType_3>, session?: loopbackContext.ResolutionSession | undefined): Promise<ValueType_3>;
            <ValueType_4>(keyWithPath: loopbackContext.BindingAddress<ValueType_4>, options: loopbackContext.ResolutionOptions): Promise<ValueType_4 | undefined>;
        };
        getSync: {
            <ValueType_5>(keyWithPath: loopbackContext.BindingAddress<ValueType_5>, session?: loopbackContext.ResolutionSession | undefined): ValueType_5;
            <ValueType_6>(keyWithPath: loopbackContext.BindingAddress<ValueType_6>, options?: loopbackContext.ResolutionOptions | undefined): ValueType_6 | undefined;
        };
        getBinding: {
            <ValueType_7 = any>(key: loopbackContext.BindingAddress<ValueType_7>): Binding<ValueType_7>;
            <ValueType_8>(key: loopbackContext.BindingAddress<ValueType_8>, options?: {
                optional?: boolean | undefined;
            } | undefined): Binding<ValueType_8> | undefined;
        };
        findOrCreateBinding: <T_8>(key: loopbackContext.BindingAddress<T_8>, policy?: loopbackContext.BindingCreationPolicy | undefined) => Binding<T_8>;
        getValueOrPromise: <ValueType_9>(keyWithPath: loopbackContext.BindingAddress<ValueType_9>, optionsOrSession?: loopbackContext.ResolutionSession | loopbackContext.ResolutionOptions | undefined) => loopbackContext.ValueOrPromise<ValueType_9 | undefined>;
        toJSON: () => loopbackContext.JSONObject;
        inspect: (options?: loopbackContext.ContextInspectOptions | undefined) => loopbackContext.JSONObject;
        on: {
            (eventName: "bind" | "unbind", listener: loopbackContext.ContextEventListener): Application;
            (event: string | symbol, listener: (...args: any[]) => void): Application;
        };
        once: {
            (eventName: "bind" | "unbind", listener: loopbackContext.ContextEventListener): Application;
            (event: string | symbol, listener: (...args: any[]) => void): Application;
        };
        addListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
        prependListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
        prependOnceListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
        removeListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
        off: (event: string | symbol, listener: (...args: any[]) => void) => Application;
        removeAllListeners: (event?: string | symbol | undefined) => Application;
        setMaxListeners: (n: number) => Application;
        getMaxListeners: () => number;
        listeners: (event: string | symbol) => Function[];
        rawListeners: (event: string | symbol) => Function[];
        emit: (event: string | symbol, ...args: any[]) => boolean;
        eventNames: () => (string | symbol)[];
        listenerCount: (type: string | symbol) => number;
    };
} & T;

Parameters

Parameter Type Description
superClass T Application class

Returns:

{ new (…args: any[]): { projectRoot: string; bootOptions?: BootOptions | undefined; booted: boolean; start(): Promise<void>; boot(): Promise<void>; booters(…booterCls: Constructor<Booter>[]): Binding[]; applicationBooter(subApp: Application & Bootable, filter?: BindingFilter | undefined): Binding<Booter>; component<C extends Component = Component>(componentCtor: Constructor<C>, nameOrOptions?: string | BindingFromClassOptions | undefined): Binding<C>; mountComponentBooters(componentInstanceOrClass: Constructor<unknown> | InstanceWithBooters): void; readonly options: loopbackContext.ApplicationConfig; readonly state: string; controller: <T_1>(controllerCtor: Constructor<T_1>, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding<T_1>; server: <T_2 extends loopbackContext.Server>(ctor: Constructor<T_2>, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding<T_2>; servers: <T_3 extends loopbackContext.Server>(ctors: Constructor<T_3>[]) => Binding<any>[]; getServer: <T_4 extends loopbackContext.Server>(target: string | Constructor<T_4>) => Promise<T_4>; onStart: (fn: () => void | PromiseLike<void>) => Binding<loopbackContext.LifeCycleObserver>; stop: () => Promise<void>; onStop: (fn: () => void | PromiseLike<void>) => Binding<loopbackContext.LifeCycleObserver>; setMetadata: (metadata: loopbackContext.ApplicationMetadata) => void; lifeCycleObserver: <T_5 extends loopbackContext.LifeCycleObserver>(ctor: Constructor<T_5>, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding<T_5>; service: <S>(cls: loopbackContext.ServiceOrProviderClass<S>, nameOrOptions?: string | loopbackContext.ServiceOptions | undefined) => Binding<S>; interceptor: (interceptor: loopbackContext.Interceptor | Constructor<loopbackContext.Provider<loopbackContext.Interceptor>>, nameOrOptions?: string | loopbackContext.InterceptorBindingOptions | undefined) => Binding<loopbackContext.Interceptor>; readonly name: string; readonly subscriptionManager: loopbackContext.ContextSubscriptionManager; readonly parent: Context | undefined; emitEvent: <T_6 extends loopbackContext.ContextEvent>(type: string, event: T_6) => void; emitError: (err: unknown) => void; bind: <ValueType = any>(key: loopbackContext.BindingAddress<ValueType>) => Binding<ValueType>; add: (binding: Binding<unknown>) => Application; configure: <ConfigValueType = any>(key?: string | loopbackContext.BindingKey<unknown> | undefined) => Binding<ConfigValueType>; getConfigAsValueOrPromise: <ConfigValueType_1>(key: loopbackContext.BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: loopbackContext.ResolutionOptions | undefined) => loopbackContext.ValueOrPromise<ConfigValueType_1 | undefined>; getConfig: <ConfigValueType_2>(key: loopbackContext.BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: loopbackContext.ResolutionOptions | undefined) => Promise<ConfigValueType_2 | undefined>; getConfigSync: <ConfigValueType_3>(key: loopbackContext.BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: loopbackContext.ResolutionOptions | undefined) => ConfigValueType_3 | undefined; unbind: (key: loopbackContext.BindingAddress<unknown>) => boolean; subscribe: (observer: loopbackContext.ContextEventObserver) => loopbackContext.Subscription; unsubscribe: (observer: loopbackContext.ContextEventObserver) => boolean; close: () => void; isSubscribed: (observer: loopbackContext.ContextObserver) => boolean; createView: <T_7 = unknown>(filter: BindingFilter, comparator?: loopbackContext.BindingComparator | undefined) => loopbackContext.ContextView<T_7>; contains: (key: loopbackContext.BindingAddress<unknown>) => boolean; isBound: (key: loopbackContext.BindingAddress<unknown>) => boolean; getOwnerContext: (key: loopbackContext.BindingAddress<unknown>) => Context | undefined; find: <ValueType_1 = any>(pattern?: string | RegExp | BindingFilter | undefined) => Readonly<Binding<ValueType_1>>[]; findByTag: <ValueType_2 = any>(tagFilter: string | RegExp | Record<string, any>) => Readonly<Binding<ValueType_2>>[]; get: { <ValueType_3>(keyWithPath: loopbackContext.BindingAddress<ValueType_3>, session?: loopbackContext.ResolutionSession | undefined): Promise<ValueType_3>; <ValueType_4>(keyWithPath: loopbackContext.BindingAddress<ValueType_4>, options: loopbackContext.ResolutionOptions): Promise<ValueType_4 | undefined>; }; getSync: { <ValueType_5>(keyWithPath: loopbackContext.BindingAddress<ValueType_5>, session?: loopbackContext.ResolutionSession | undefined): ValueType_5; <ValueType_6>(keyWithPath: loopbackContext.BindingAddress<ValueType_6>, options?: loopbackContext.ResolutionOptions | undefined): ValueType_6 | undefined; }; getBinding: { <ValueType_7 = any>(key: loopbackContext.BindingAddress<ValueType_7>): Binding<ValueType_7>; <ValueType_8>(key: loopbackContext.BindingAddress<ValueType_8>, options?: { optional?: boolean | undefined; } | undefined): Binding<ValueType_8> | undefined; }; findOrCreateBinding: <T_8>(key: loopbackContext.BindingAddress<T_8>, policy?: loopbackContext.BindingCreationPolicy | undefined) => Binding<T_8>; getValueOrPromise: <ValueType_9>(keyWithPath: loopbackContext.BindingAddress<ValueType_9>, optionsOrSession?: loopbackContext.ResolutionSession | loopbackContext.ResolutionOptions | undefined) => loopbackContext.ValueOrPromise<ValueType_9 | undefined>; toJSON: () => loopbackContext.JSONObject; inspect: (options?: loopbackContext.ContextInspectOptions | undefined) => loopbackContext.JSONObject; on: { (eventName: “bind” | “unbind”, listener: loopbackContext.ContextEventListener): Application; (event: string | symbol, listener: (…args: any[]) => void): Application; }; once: { (eventName: “bind” | “unbind”, listener: loopbackContext.ContextEventListener): Application; (event: string | symbol, listener: (…args: any[]) => void): Application; }; addListener: (event: string | symbol, listener: (…args: any[]) => void) => Application; prependListener: (event: string | symbol, listener: (…args: any[]) => void) => Application; prependOnceListener: (event: string | symbol, listener: (…args: any[]) => void) => Application; removeListener: (event: string | symbol, listener: (…args: any[]) => void) => Application; off: (event: string | symbol, listener: (…args: any[]) => void) => Application; removeAllListeners: (event?: string | symbol | undefined) => Application; setMaxListeners: (n: number) => Application; getMaxListeners: () => number; listeners: (event: string | symbol) => Function[]; rawListeners: (event: string | symbol) => Function[]; emit: (event: string | symbol, …args: any[]) => boolean; eventNames: () => (string | symbol)[]; listenerCount: (type: string | symbol) => number; }; } & T

A new class that extends the super class with boot related methods