First check-in of the code from the Obsidian Prj project.

This commit is contained in:
2024-08-14 19:40:52 +02:00
parent 1341427590
commit 6c4db19926
14 changed files with 495 additions and 0 deletions

35
src/functions/Register.ts Normal file
View 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
View 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);
}