@akala/core
Version:
82 lines (81 loc) • 3.06 kB
TypeScript
import "reflect-metadata";
import { Injector, LocalInjector, type Resolvable } from './shared.js';
/**
* A simple dependency injection container that provides basic resolution capabilities.
* This class extends LocalInjector and manages injectables through a straightforward key-value store.
*/
export declare class SimpleInjector extends LocalInjector {
/**
* Creates an instance of SimpleInjector.
* @param {Injector | null} [parent=null] - The parent injector to fallback to when resolving dependencies.
*/
constructor(parent?: Injector | null);
private readonly notifier;
/**
* Sets the injectables.
* @param {{ [key: string]: unknown }} value - The injectables to set.
*/
setInjectables(value: {
[key: string]: unknown;
}): void;
/**
* Returns the keys of the injectables.
* @returns {string[]} The keys of the injectables.
*/
keys(): string[];
/**
* Merges another SimpleInjector into this one.
* @param {SimpleInjector} i - The SimpleInjector to merge.
*/
merge(i: SimpleInjector): void;
/**
* Notifies listeners of a change.
* @param {string} name - The name of the property that changed.
* @param {PropertyDescriptor} [value] - The new value of the property.
*/
protected notify(name: string, value?: PropertyDescriptor): void;
/**
* Registers a handler to be called when a value is resolved.
* @param {string} name - The name of the value to resolve.
* @returns {PromiseLike<T>} A promise that resolves to the value.
*/
onResolve<T = unknown>(name: string): PromiseLike<T>;
/**
* Registers a handler to be called when a value is resolved.
* @param {string} name - The name of the value to resolve.
* @param {(value: T) => void} handler - The handler to call when the value is resolved.
*/
onResolve<T = unknown>(name: string, handler: (value: T) => void): void;
private resolveKeys;
/**
* Resolves a value.
* @param {Resolvable} param - The parameter to resolve.
* @returns {T} The resolved value.
*/
resolve<T>(param: Resolvable): T;
private inspecting;
/**
* Inspects the injectables.
*/
inspect(): void;
private browsingForJSON;
/**
* Converts the injectables to JSON.
* @returns {object} The injectables as JSON.
*/
toJSON(): {};
protected injectables: {};
/**
* Unregisters an injectable.
* @param {string} name - The name of the injectable to unregister.
*/
unregister(name: string): void;
/**
* Registers a descriptor for an injectable.
* @param {string | symbol} name - The name of the injectable.
* @param {PropertyDescriptor} value - The descriptor of the injectable.
* @param {boolean} [override] - Whether to override an existing injectable.
*/
registerDescriptor(name: string | symbol, value: PropertyDescriptor, override?: boolean): void;
}
export declare const defaultInjector: SimpleInjector;