Add dependency management classes and interfaces

- Introduced Type and NamedType classes for type management
- Implemented IDependencyProvider interface for dependency provision
- Updated DependencyManager with a new lifecycle type 'service'
- Added methods for type comparison and URN generation in Type and NamedType
This commit is contained in:
2025-10-30 03:15:41 -04:00
parent 1587ed7428
commit 64407db695
4 changed files with 49 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ type Registration = {
/**
* Lifecycle types:
* - 'singleton': A single shared instance cached for the lifetime of the manager
* - 'sergice': A single shared instance cached for the lifetime of the manager
* - 'transient': A new instance created on each resolve (transient)
*/
type Lifecycle = 'transient' | 'singleton';

22
src/di/NamedType.ts Normal file
View File

@@ -0,0 +1,22 @@
import { Type } from "./Type";
export class NamedType extends Type {
private readonly _name: string;
constructor(name: string, type: string) {
super(type);
this._name = name;
}
public getName(): string {
return this._name;
}
public equals(other: NamedType): boolean {
return super.equal(other) && other instanceof NamedType && this.getName() === other.getName();
}
public override toURN(): string {
return 'urn:namedtype:' + super.getType() + '#' + this._name;
}
}

19
src/di/Type.ts Normal file
View File

@@ -0,0 +1,19 @@
export class Type {
private readonly _type: string;
constructor(type: string) {
this._type = type;
}
public getType(): string {
return this._type;
}
public equal(other: Type): boolean {
return other instanceof Type && this.getType() === other.getType();
}
public toURN() {
return 'urn:type:' + this._type;
}
}

View File

@@ -0,0 +1,7 @@
import type { Type } from "../Type";
import type { NamedType } from "../NamedType";
export interface IDependencyProvider {
canProvide(type: Type | NamedType): boolean;
provide(type: Type | NamedType): unknown;
}