UNPKG

@supercharge/container

Version:

The Supercharge container package

95 lines (94 loc) 2.83 kB
import { Class, Container as ContainerContract, BindingFactory } from '@supercharge/contracts'; export declare class Container implements ContainerContract { /** * Stores the container bindings. */ private bindings; /** * Stores the registered aliases. */ private readonly aliases; /** * Stores the singleton instances. */ private singletons; /** * Create a new container instance. */ constructor(); /** * Register a binding in the container. */ bind(namespace: string | Class, factory: BindingFactory<any>, options?: { singleton?: boolean; }): this; /** * Ensure the given `namespace` is a string or a class constructor. */ private ensureNamespace; /** * Register a shared binding (singleton) in the container. */ singleton(namespace: string | Class, factory: BindingFactory<any>): this; /** * Determine whether the given `namespace` is bound in the container. */ hasBinding(namespace: string | Class): boolean; /** * Determine whether the given `namespace` is bound as a singleton in the container. */ hasSingletonBinding(namespace: string | Class): boolean; /** * Returns the resolved namespace identifier as a string. */ private resolveNamespace; /** * Determine whether the given `namespace` is a singleton. */ isSingleton(namespace: string | Class): boolean; /** * Resolve the given namespace from the container. */ make<T = any>(namespace: string): T; make<T>(namespace: Class<T>): T; /** * Run the factory function for the given binding that resolves the related instance. */ private build; /** * Returns the factory callback for the given namespace. */ private getFactoryFor; /** * Returns a factory function for the given namespace. */ resolveFactoryFor(namespace: string | Class): any; /** * Returns a factory function for the given class constructor. */ createFactoryFor(Constructor: Class): any; /** * Determine whether the given `namespace` is an alias. */ getAlias(namespace: string | Class): string; /** * Determine whether the given `namespace` is an alias. */ isAlias(namespace: string | Class): boolean; /** * Alias a binding to a different name. */ alias(namespace: string | Class, alias: string | Class): this; /** * Assign the given `alias` to the concrete `namespace`. */ private addAlias; /** * Remove a resolved instance from the (singleton) cache. */ forgetInstance(namespace: string | Class): this; /** * Flush all bindings and resolved instances from the containter. */ flush(): this; }