Refactor DI container for better structure and clarity
- Moved `TSinjex` class to `classes` directory for better organization. - Updated imports across the codebase to reflect the new location of `TSinjex`. - Introduced `Identifier` type to standardize dependency identifiers. - Enhanced JSDoc comments for improved clarity and consistency. - Adjusted error messages for `DependencyResolutionError` to provide clearer information. - Updated and expanded decorator and function types to use `Identifier` type.
This commit is contained in:
@@ -1,33 +1,37 @@
|
||||
import { TSinjex } from '../TSinjex';
|
||||
import { Identifier } from 'src/types/Identifier';
|
||||
import { TSinjex } from '../classes/TSinjex';
|
||||
|
||||
/**
|
||||
* Register a dependency.
|
||||
* @param identifier The identifier of the dependency.
|
||||
* @param identifier The identifier used to register the class in the DI container.
|
||||
* @see {@link Identifier} for more information on identifiers..
|
||||
* @param dependency The dependency to register.
|
||||
*/
|
||||
export function register<T>(identifier: string, dependency: T): void;
|
||||
export function register<T>(identifier: Identifier, dependency: T): void;
|
||||
|
||||
/**
|
||||
* Register a dependency.
|
||||
* @param identifier The identifier of the dependency.
|
||||
* @param identifier The identifier used to register the class in the DI container.
|
||||
* @see {@link Identifier} for more information on identifiers.
|
||||
* @param dependency The dependency to register.
|
||||
* @param deprecated A warning is logged when the dependency is resolved.
|
||||
*/
|
||||
export function register<T>(
|
||||
identifier: string,
|
||||
identifier: Identifier,
|
||||
dependency: T,
|
||||
deprecated?: true,
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Register a dependency.
|
||||
* @param identifier The identifier of the dependency.
|
||||
* @param identifier The identifier used to register the class in the DI container.
|
||||
* @see {@link Identifier} for more information on identifiers.
|
||||
* @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,
|
||||
identifier: Identifier,
|
||||
dependency: T,
|
||||
deprecated?: boolean,
|
||||
): void {
|
||||
|
@@ -1,32 +1,39 @@
|
||||
import { Identifier } from 'src/types/Identifier';
|
||||
import { TSinjex } from '../classes/TSinjex';
|
||||
import { DependencyResolutionError } from '../interfaces/Exceptions';
|
||||
import { TSinjex } from '../TSinjex';
|
||||
|
||||
/**
|
||||
* Resolve a dependency.
|
||||
* @param identifier The identifier of the dependency.
|
||||
* @param identifier The identifier used to register the class in the DI container.
|
||||
* @see {@link Identifier} for more information on identifiers.
|
||||
* @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: Identifier): T;
|
||||
|
||||
/**
|
||||
* Resolve a dependency
|
||||
* @param identifier The identifier of the dependency.
|
||||
* @param identifier The identifier used to register the class in the DI container.
|
||||
* @see {@link Identifier} for more information on identifiers.
|
||||
* @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: Identifier,
|
||||
necessary: false,
|
||||
): T | undefined;
|
||||
|
||||
/**
|
||||
* Resolve a dependency.
|
||||
* @param identifier The identifier of the dependency.
|
||||
* @param identifier The identifier used to register the class in the DI container.
|
||||
* @see {@link Identifier} for more information on identifiers.
|
||||
* @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,
|
||||
identifier: Identifier,
|
||||
necessary?: boolean,
|
||||
): T | undefined {
|
||||
return TSinjex.getInstance().resolve<T>(identifier, necessary);
|
||||
|
Reference in New Issue
Block a user