Add Dependency Injection example and core interfaces. Implement Inject class for managing scopes and instances, along with InstanceProvider, IntegerConstantProvider, and StringConstantProvider for dependency resolution.

This commit is contained in:
2025-10-25 17:51:44 -04:00
parent 0de4b9314a
commit 00332dc6b1
7 changed files with 212 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
/**
* Copyright 2025 Phenix Real Time Solutions, Inc. Confidential and Proprietary. All Rights Reserved.
*/
import type {IDependencyProvider} from './IDependencyProvider';
import {Type} from './Type';
import {NamedType} from './NamedType';
/**
* A dependency provider for integer constants.
* Uses NamedType where the name is parsed as an integer.
*/
export class IntegerConstantProvider implements IDependencyProvider {
public canProvide(type: Type): boolean {
if (!(type instanceof Type)) {
throw new Error('Must provide a valid type');
}
return type instanceof NamedType && type.getType() === 'di/IntegerConstantProvider';
}
public async provide(type: Type): Promise<number> {
if (!(type instanceof NamedType)) {
throw new Error('Must provide a NamedType');
}
return parseInt(type.getName(), 10);
}
public toString(): string {
return 'IntegerConstantProvider';
}
}