import type { Service } from "./Service"; import type { ServiceFactory } from "./ServiceFactory"; import type { ServiceRegistry } from "./ServiceRegistry"; import type { Dependency } from "./decorator.inject"; /** * A unique ID for a service. */ export type ServiceId = string; /** * Indicates that there is a cycle in the dependency graph. */ export declare class CircularDependencyError extends Error { } /** * An error that is thrown when a required dependency can't be resolved. */ export declare class UnresolvedDependencyError extends Error { /** * The object with the dependency. */ object: object; /** * Details of the dependency. */ dependency: Dependency; constructor(object: object, dependency: Dependency, message?: string); private static _createMessage; } /** * A simple dependency injection container used by the framework. Both built-in * services and custom services defined in config can be injected into models * and other services by adding an `@inject(...)` decorator on a property with * the service ID. * * Services are lazily created as they are needed to satisfy dependencies. */ export declare class InjectionContainer implements Iterable { private readonly _services; private readonly _initializedServices; private _initializePromise; private _isInitialized; constructor(); /** * A registry of available services. If not specified, a default one will be * used. */ get registry(): ServiceRegistry; set registry(value: ServiceRegistry); /** * A factory for creating services. If not specified, a default one will be * used. */ get factory(): ServiceFactory; set factory(value: ServiceFactory); /** * Determines whether the container is initialized. */ get isInitialized(): boolean; /** * Initializes the container. */ initialize(): Promise; /** * Determines whether the container has a service with the given ID. * * @param id The service ID. */ has(id: ServiceId): boolean; /** * Gets a service by ID. * * Normally services should be injected instead (see {@link inject}). This * method is for the rare case when a service needs to be dynamically looked * up by ID. * * @param id The service ID. */ get(id: ServiceId): Promise; /** * Iterates over all the service IDs. */ [Symbol.iterator](): Iterator; /** * Satisfies the dependencies of an object, expressed by its `@inject()` * decorators on properties. * * @param obj The object with dependencies. * @throws {@link CircularDependencyError} If a cycle is detected. * @throws {@link UnresolvedDependencyError} If one or more required * dependencies can't be resolved. */ inject(obj: object): Promise; /** * Manually sets the service implementation to use for a given ID. * * This will override whatever is defined in the {@link ServiceRegistry}. * * @param id The service ID. * @param service The service. */ set(id: ServiceId, service: object): void; /** * Clears all services that were registered via set(). */ clear(): void; /** * Invokes the destroy() hook on all services that have been instantiated. */ destroy(): Promise; private _get; private _inject; }