Rename DIContainer to TSInjex and refactor interfaces

- Renamed DIContainer class and related references to TSInjex to better indicate its purpose as a TypeScript-based dependency injection container.
- Extracted IDependency interface to a separate file to improve modularity.
- Split the ITSInjex interface into ITSInjexRegister and ITSInjexResolve, then extended them in a new ITSInjex interface to clarify the separation of concerns.
- Updated tests and decorators to reflect the renaming and interface changes.
- Adjusted helper, functions, and index export to align with the new TSInjex structure.
This commit is contained in:
2024-08-14 20:21:05 +02:00
committed by Max P.
parent 8d607c7f0c
commit 3dbbfc8e1e
13 changed files with 106 additions and 59 deletions

View File

@@ -1,11 +1,11 @@
import { DIContainer } from 'src/DIContainer';
import { TSInjex } from 'src/TSInjex';
/**
* 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;
export function register<T>(identifier: string, dependency: T): void;
/**
* Register a dependency.
@@ -13,7 +13,7 @@ export function Register<T>(identifier: string, dependency: T): void;
* @param dependency The dependency to register.
* @param deprecated A warning is logged when the dependency is resolved.
*/
export function Register<T>(
export function register<T>(
identifier: string,
dependency: T,
deprecated?: true,
@@ -26,10 +26,10 @@ export function Register<T>(
* @param deprecated If true, the dependency is deprecated => a warning
* is logged when the dependency is resolved.
*/
export function Register<T>(
export function register<T>(
identifier: string,
dependency: T,
deprecated?: boolean,
): void {
DIContainer.getInstance().register(identifier, dependency, deprecated);
TSInjex.getInstance().register(identifier, dependency, deprecated);
}

View File

@@ -1,5 +1,5 @@
import { DIContainer } from '../DIContainer';
import { DependencyResolutionError } from '../interfaces/Exceptions';
import { TSInjex } from '../TSInjex';
/**
* Resolve a dependency.
@@ -7,7 +7,7 @@ import { DependencyResolutionError } from '../interfaces/Exceptions';
* @returns The resolved dependency.
* @throws A {@link DependencyResolutionError} if the dependency is not found.
*/
export function Resolve<T>(identifier: string): T;
export function resolve<T>(identifier: string): T;
/**
* Resolve a dependency
@@ -15,7 +15,7 @@ export function Resolve<T>(identifier: string): T;
* @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;
export function resolve<T>(identifier: string, necessary: false): T | undefined;
/**
* Resolve a dependency.
@@ -25,9 +25,9 @@ export function Resolve<T>(identifier: string, necessary: false): T | undefined;
* 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>(
export function resolve<T>(
identifier: string,
necessary?: boolean,
): T | undefined {
return DIContainer.getInstance().resolve<T>(identifier, necessary);
return TSInjex.getInstance().resolve<T>(identifier, necessary);
}