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,17 +1,19 @@
|
||||
import { TSinjex } from '../TSinjex';
|
||||
import { Identifier } from 'src/types/Identifier';
|
||||
import { TSinjex } from '../classes/TSinjex';
|
||||
import { InitDelegate } from '../types/InitDelegate';
|
||||
|
||||
/**
|
||||
* A decorator to register an instance of a class in the DI (Dependency Injection) container.
|
||||
* The instance is created only when it is first needed (Lazy Initialization).
|
||||
* @template TargetType The type of the class whose instance is to be registered.
|
||||
* @param identifier The identifier used to register the instance in the DI container.
|
||||
* @see {@link Identifier} for more information on identifiers.
|
||||
* @param init An optional initializer function which get the constructor of the class
|
||||
* as input and returns an instance of the class.
|
||||
* @returns A function that is applied as a decorator to the class.
|
||||
* @see {@link InitDelegate} for more information on initializer functions.
|
||||
* @returns The decorator function to be applied on the class.
|
||||
* @example
|
||||
* ```ts
|
||||
* \@RegisterInstance('MyClassInstanceIdentifier', arg1, arg2)
|
||||
* \@RegisterInstance('MyClassInstanceIdentifier', (constructor) => new constructor())
|
||||
* class MyClass {
|
||||
* // ...
|
||||
* }
|
||||
@@ -20,7 +22,7 @@ import { InitDelegate } from '../types/InitDelegate';
|
||||
export function RegisterInstance<
|
||||
TargetType extends new (..._args: unknown[]) => InstanceType<TargetType>,
|
||||
>(
|
||||
identifier: string,
|
||||
identifier: Identifier,
|
||||
init?: InitDelegate<
|
||||
TargetType & { new (..._args: unknown[]): InstanceType<TargetType> },
|
||||
InstanceType<TargetType>
|
||||
|
Reference in New Issue
Block a user