UNPKG

react-model-view-viewmodel

Version:

A library for developing ReactJS applications using Model-View-ViewModel, inspired by .NET.

221 lines (220 loc) 11.1 kB
import type { IDependencyContainer, ConfigurableDependency, DependencyFactoryCallback } from './IDependencyContainer'; import { type IDependencyResolver, type ResolvableSimpleDependency, type ComplexDependency, DependencyToken } from './IDependencyResolver'; /** * Represents a dependency container for configuring and later on resolving dependencies similar to a dependency injection mechanism. */ export declare class DependencyContainer implements IDependencyContainer, IDependencyResolver { private static _dependencyResolutionChain; private readonly _parent; private readonly _singletonDependencyFactories; private readonly _scopedDependencyFactories; /** * Initializes a new instance of the {@linkcode DependencyContainer} class. * @param parent Optional, a parent container to use as fallback when resolving dependencies. */ constructor(parent?: DependencyContainer); /** * Creates a scoped dependency resolver. All scoped configured dependencies are resolved for each scope individually, * while singletons are unique from the scope that configured them downwards. * @returns Returns a scoped dependency resolver. */ createScope(): IDependencyResolver; /** * Registers the provided type as a singleton dependency. * @template T The dependency type to configure. * @param type The type to configure. * @returns Returns the dependency container. */ registerSingletonType<T>(type: ConfigurableDependency<T>): DependencyContainer; /** * Registers the provided type as a singleton dependency. * @template T The dependency type to configure. * @param type The type to configure. * @param factoryCallback A callback for initializing an instace of the given type. * @returns Returns the dependency container. */ registerSingletonType<T>(type: ConfigurableDependency<T>, factoryCallback: DependencyFactoryCallback<T>): DependencyContainer; /** * Registers the provided instance for the given token. * @template T The dependency type to configure. * @param token The token used to resolve dependencies. * @param instance The instance to return when resolving the dependency token. * @returns Returns the dependency container. */ registerInstanceToToken<T>(token: DependencyToken<T>, instance: T): DependencyContainer; /** * Registers the provided type for the given token as a singleton dependency. * @template T The dependency type to configure. * @param token The token used to resolve dependencies. * @param type The type to configure. * @returns Returns the dependency container. */ registerSingletonTypeToToken<T>(token: DependencyToken<T>, type: ConfigurableDependency<T>): DependencyContainer; /** * Registers the provided callback for the given token as a singleton dependency. * @template T The dependency type to configure. * @param token The token used to resolve dependencies. * @param factoryCallback A callback for initializing an instace of the given type. * @returns Returns the dependency container. */ registerSingletonFactoryToToken<T>(token: DependencyToken<T>, factoryCallback: DependencyFactoryCallback<T>): DependencyContainer; /** * Registers the provided type as a scoped dependency. * @template T The dependency type to configure. * @param type The type to configure. * @returns Returns the dependency container. */ registerScopedType<T>(type: ConfigurableDependency<T>): DependencyContainer; /** * Registers the provided type as a scoped dependency. * @template T The dependency type to configure. * @param type The type to configure. * @param factoryCallback A callback for initializing an instace of the given type. * @returns Returns the dependency container. */ registerScopedType<T>(type: ConfigurableDependency<T>, factoryCallback: DependencyFactoryCallback<T>): DependencyContainer; /** * Registers the provided type for the given token as a scoped dependency. * @template T The dependency type to configure. * @param token The token used to resolve dependencies. * @param type The type to configure. * @returns Returns the dependency container. */ registerScopedTypeToToken<T>(token: DependencyToken<T>, type: ConfigurableDependency<T>): DependencyContainer; /** * Registers the provided callback for the given token as a scoped dependency. * @template T The dependency type to configure. * @param token The token used to resolve dependencies. * @param factoryCallback A callback for initializing an instace of the given type. * @returns Returns the dependency container. */ registerScopedFactoryToToken<T>(token: DependencyToken<T>, factoryCallback: DependencyFactoryCallback<T>): DependencyContainer; /** * Registers the provided type as a transient dependency. * @template T The dependency type to configure. * @param type The type to configure. * @param factoryCallback A callback for initializing an instace of the given type. * @returns Returns the dependency container. */ registerTransientType<T>(type: ConfigurableDependency<T>, factoryCallback: DependencyFactoryCallback<T>): DependencyContainer; /** * Registers the provided type for the given token as a transient dependency. * @template T The dependency type to configure. * @param token The token used to resolve dependencies. * @param type The type to configure. * @returns Returns the dependency container. */ registerTransientTypeToToken<T>(token: DependencyToken<T>, type: ConfigurableDependency<T>): DependencyContainer; /** * Registers the provided callback for the given token as a transient dependency. * @template T The dependency type to configure. * @param token The token used to resolve dependencies. * @param factoryCallback A callback for initializing an instace of the given type. * @returns Returns the dependency container. */ registerTransientFactoryToToken<T>(token: DependencyToken<T>, factoryCallback: DependencyFactoryCallback<T>): DependencyContainer; /** * Resolves a dependency based on its configuration, if any. All unconfigured dependencies are transient. * * @template T The dependency type to resolve. * * @param dependency The dependnecy to resolve. * * @returns The resolved dependency. */ resolve<T>(dependency: ResolvableSimpleDependency<T>): T; /** * Resolves a dependency based on its configuration, if any. All unconfigured dependencies are transient. * * @template T The dependency type to resolve. * * @param dependency The dependnecy to resolve. * * @returns The resolved dependency. * * @ignore This is overload is not relevant for wiki documentation. */ resolve<T>(dependency: ResolvableSimpleDependency<T> | null): T | null; /** * Resolves a dependency based on its configuration, if any. All unconfigured dependencies are transient. * * @template T The dependency type to resolve. * * @param dependency The dependnecy to resolve. * * @returns The resolved dependency. * * @ignore This is overload is not relevant for wiki documentation. */ resolve<T>(dependency: ResolvableSimpleDependency<T> | undefined): T | undefined; /** * Resolves a dependency based on its configuration, if any. All unconfigured dependencies are transient. * * @template T The dependency type to resolve. * * @param dependency The dependnecy to resolve. * * @returns The resolved dependency. * * @ignore This is overload is not relevant for wiki documentation. */ resolve<T>(dependency: ResolvableSimpleDependency<T> | null | undefined): T | null | undefined; /** * Resolves a complex dependency. All such dependencies are transient as they require * additional dependencies on the constructor. * * @template T The dependency type to resolve. * @template TAdditional A tuple representing additional parameters required by the constructor. * * @param dependency The complex dependnecy to resolve. * @param additionalDependencies Additional dependencies requested by the constructor besides the dependency resolver. * * @returns The resolved dependency. */ resolve<T, TAdditional extends readonly any[]>(dependency: ComplexDependency<T, TAdditional>, additionalDependencies: TAdditional): T; /** * Resolves a complex dependency. All such dependencies are transient as they require * additional dependencies on the constructor. * * @template T The dependency type to resolve. * @template TAdditional A tuple representing additional parameters required by the constructor. * * @param dependency The complex dependnecy to resolve. * @param additionalDependencies Additional dependencies requested by the constructor besides the dependency resolver. * * @returns The resolved dependency. * * @ignore This is overload is not relevant for wiki documentation. */ resolve<T, TAdditional extends readonly any[]>(dependency: ComplexDependency<T, TAdditional> | null, additionalDependencies: TAdditional): T | null; /** * Resolves a complex dependency. All such dependencies are transient as they require * additional dependencies on the constructor. * * @template T The dependency type to resolve. * @template TAdditional A tuple representing additional parameters required by the constructor. * * @param dependency The complex dependnecy to resolve. * @param additionalDependencies Additional dependencies requested by the constructor besides the dependency resolver. * * @returns The resolved dependency. * * @ignore This is overload is not relevant for wiki documentation. */ resolve<T, TAdditional extends readonly any[]>(dependency: ComplexDependency<T, TAdditional> | undefined, additionalDependencies: TAdditional): T | undefined; /** * Resolves a complex dependency. All such dependencies are transient as they require * additional dependencies on the constructor. * * @template T The dependency type to resolve. * @template TAdditional A tuple representing additional parameters required by the constructor. * * @param dependency The complex dependnecy to resolve. * @param additionalDependencies Additional dependencies requested by the constructor besides the dependency resolver. * * @returns The resolved dependency. * * @ignore This is overload is not relevant for wiki documentation. */ resolve<T, TAdditional extends readonly any[]>(dependency: ComplexDependency<T, TAdditional> | null | undefined, additionalDependencies: TAdditional): T | null | undefined; }