First check-in of the code from the Obsidian Prj project.
This commit is contained in:
35
src/functions/Register.ts
Normal file
35
src/functions/Register.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { DIContainer } from 'src/DIContainer';
|
||||
|
||||
/**
|
||||
* Register a dependency.
|
||||
* @param identifier The identifier of the dependency.
|
||||
* @param dependency The dependency to register.
|
||||
*/
|
||||
export function Register<T>(identifier: string, dependency: T): void;
|
||||
|
||||
/**
|
||||
* Register a dependency.
|
||||
* @param identifier The identifier of the dependency.
|
||||
* @param dependency The dependency to register.
|
||||
* @param deprecated A warning is logged when the dependency is resolved.
|
||||
*/
|
||||
export function Register<T>(
|
||||
identifier: string,
|
||||
dependency: T,
|
||||
deprecated?: true,
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Register a dependency.
|
||||
* @param identifier The identifier of the dependency.
|
||||
* @param dependency The dependency to register.
|
||||
* @param deprecated If true, the dependency is deprecated => a warning
|
||||
* is logged when the dependency is resolved.
|
||||
*/
|
||||
export function Register<T>(
|
||||
identifier: string,
|
||||
dependency: T,
|
||||
deprecated?: boolean,
|
||||
): void {
|
||||
DIContainer.getInstance().register(identifier, dependency, deprecated);
|
||||
}
|
33
src/functions/Resolve.ts
Normal file
33
src/functions/Resolve.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { DIContainer } from '../DIContainer';
|
||||
import { DependencyResolutionError } from '../interfaces/Exceptions';
|
||||
|
||||
/**
|
||||
* Resolve a dependency.
|
||||
* @param identifier The identifier of the dependency.
|
||||
* @returns The resolved dependency.
|
||||
* @throws A {@link DependencyResolutionError} if the dependency is not found.
|
||||
*/
|
||||
export function Resolve<T>(identifier: string): T;
|
||||
|
||||
/**
|
||||
* Resolve a dependency
|
||||
* @param identifier The identifier of the dependency.
|
||||
* @param necessary The dependency is **not** necessary.
|
||||
* @returns The resolved dependency or undefined if the dependency is not found.
|
||||
*/
|
||||
export function Resolve<T>(identifier: string, necessary: false): T | undefined;
|
||||
|
||||
/**
|
||||
* Resolve a dependency.
|
||||
* @param identifier The identifier of the dependency.
|
||||
* @param necessary If true, throws an error if the dependency is not found.
|
||||
* @returns The resolved dependency or undefined if the dependency is not necessary
|
||||
* and not found, or throws an error if the dependency is necessary and not found.
|
||||
* @throws A {@link DependencyResolutionError} if the dependency is not found and necessary.
|
||||
*/
|
||||
export function Resolve<T>(
|
||||
identifier: string,
|
||||
necessary?: boolean,
|
||||
): T | undefined {
|
||||
return DIContainer.getInstance().resolve<T>(identifier, necessary);
|
||||
}
|
Reference in New Issue
Block a user