updates
This commit is contained in:
@@ -7,13 +7,12 @@ type Registration = {
|
||||
/**
|
||||
* Lifecycle types:
|
||||
* - 'singleton': A single shared instance cached for the lifetime of the manager
|
||||
* - 'instance': A new instance created on each resolve (transient)
|
||||
* - 'service': A new instance created on each resolve (transient, alias for 'instance')
|
||||
* - 'transient': A new instance created on each resolve (transient)
|
||||
*/
|
||||
type Lifecycle = 'instance' | 'service' | 'singleton';
|
||||
type Lifecycle = 'transient' | 'singleton';
|
||||
|
||||
export class DependencyManager {
|
||||
private static readonly _supportedLifecycles: string[] = ['instance', 'service', 'singleton'];
|
||||
private static readonly _supportedLifecycles: Lifecycle[] = ['transient', 'singleton'];
|
||||
private readonly _resolving: Set<string>;
|
||||
private readonly _registrations: Map<string, Registration>;
|
||||
private readonly _singletons: Map<string, unknown>;
|
||||
@@ -32,7 +31,7 @@ export class DependencyManager {
|
||||
* @param lifecycle - Lifecycle of the instance ('singleton', 'instance', or 'service'). Default: 'singleton'
|
||||
* @throws Error if name is already registered or lifecycle is invalid
|
||||
*/
|
||||
public register(name: string, Class: new (...args: any[]) => any, dependencies: string[], lifecycle = 'singleton') {
|
||||
public register(name: string, Class: new (...args: any[]) => any, dependencies: string[], lifecycle: Lifecycle = 'singleton') {
|
||||
if (this._registrations.has(name)) {
|
||||
throw new Error(`Error: [${name}] is already registered`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user