@@ -9,6 +9,7 @@ import { IInjector } from "./definitions/yok";
99import { ICommandArgument , ICommand } from "./definitions/commands" ;
1010import { IKeyCommand , IValidKeyName } from "./definitions/key-commands" ;
1111import { Injector } from "./di/injector" ;
12+ import type { Provider } from "./di/providers" ;
1213
1314/**
1415 * The legacy global facade binding. New code should obtain the container via
@@ -47,22 +48,20 @@ export interface IDependency {
4748}
4849
4950/**
50- * The Yok facade: the externally reachable injector surface (every IInjector
51- * member, the global $injector, subclassability) kept intact while storage and
52- * resolution live in the token-based `Injector` (lib/common/di). Command
53- * routing, the key-command namespace, and the public-API builder still live
54- * here — they are separate subsystems that only share the container .
51+ * The Yok facade IS the token-based `Injector` — it extends it — plus the
52+ * legacy surface: command routing, the key-command namespace, the module
53+ * loader, and the public-API builder. Those subsystems historically shared
54+ * the container object and migrate out separately; until then they live here,
55+ * individually marked @deprecated .
5556 */
56- export class Yok implements IInjector {
57+ export class Yok extends Injector implements IInjector {
5758 /**
5859 * @deprecated Escape hatch of the legacy require-time module map.
5960 */
6061 public overrideAlreadyRequiredModule : boolean = false ;
6162
62- /** The token-based container backing this facade. */
63- private container = new Injector ( ) ;
64-
6563 constructor ( ) {
64+ super ( ) ;
6665 this . register ( "injector" , this ) ;
6766 }
6867
@@ -76,11 +75,6 @@ export class Yok implements IInjector {
7675 private KEY_COMMANDS_NAMESPACE : string = "keyCommands" ;
7776 private hierarchicalCommands : IDictionary < string [ ] > = { } ;
7877
79- /** New-style access to the backing container, for token-based registration. */
80- public get di ( ) : Injector {
81- return this . container ;
82- }
83-
8478 /**
8579 * @deprecated Path-based command registration; slated for replacement by
8680 * manifest-declared commands.
@@ -94,7 +88,7 @@ export class Yok implements IInjector {
9488 if ( commands . length > 1 ) {
9589 if (
9690 _ . startsWith ( commands [ 1 ] , "*" ) &&
97- this . container . has ( this . createCommandName ( commands [ 0 ] ) ) &&
91+ this . has ( this . createCommandName ( commands [ 0 ] ) ) &&
9892 ! this . synthesizedParents . has ( commands [ 0 ] )
9993 ) {
10094 throw new Error (
@@ -115,7 +109,7 @@ export class Yok implements IInjector {
115109
116110 if (
117111 commands . length > 1 &&
118- ! this . container . has ( this . createCommandName ( commands [ 0 ] ) )
112+ ! this . has ( this . createCommandName ( commands [ 0 ] ) )
119113 ) {
120114 this . require ( this . createCommandName ( commands [ 0 ] ) , file ) ;
121115 if ( commands [ 1 ] && ! commandName . match ( / \| \* / ) ) {
@@ -191,7 +185,7 @@ export class Yok implements IInjector {
191185 }
192186
193187 private resolveInstance ( name : string ) : any {
194- let classInstance = this . container . peek ( name ) ;
188+ let classInstance = this . peek ( name ) ;
195189 if ( ! classInstance ) {
196190 classInstance = this . resolve ( name ) ;
197191 }
@@ -207,11 +201,11 @@ export class Yok implements IInjector {
207201 ? relativePath
208202 : file ;
209203
210- if ( ! this . container . has ( name ) || this . overrideAlreadyRequiredModule ) {
204+ if ( ! this . has ( name ) || this . overrideAlreadyRequiredModule ) {
211205 // Yok replaced the whole record on an allowed re-require, dropping any
212206 // resolver and cached instances with it — preserved via remove().
213- this . container . remove ( name ) ;
214- this . container . register ( {
207+ this . remove ( name ) ;
208+ this . register ( {
215209 provide : name ,
216210 useLazyRequire : ( ) => require ( dependencyPath ) ,
217211 } ) ;
@@ -427,22 +421,33 @@ export class Yok implements IInjector {
427421 }
428422
429423 /**
430- * @deprecated Use provide() / Injector.register from lib/common/di (via
431- * `Yok.di`); a contract's token name keeps string spellings resolvable.
424+ * @deprecated Legacy name-based registration. Use a Provider (the overload
425+ * below) or provide(); a contract's token name keeps string spellings
426+ * resolvable.
432427 */
433- public register ( name : string , resolver : any , shared ?: boolean ) : void {
434- shared = shared === undefined ? true : shared ;
428+ public register ( name : string , resolver : any , shared ?: boolean ) : void ;
429+ public register ( providers : Provider | Provider [ ] ) : void ;
430+ public register (
431+ nameOrProviders : string | Provider | Provider [ ] ,
432+ resolver ?: any ,
433+ shared ?: boolean ,
434+ ) : void {
435+ if ( typeof nameOrProviders !== "string" ) {
436+ super . register ( nameOrProviders ) ;
437+ return ;
438+ }
435439
440+ shared = shared === undefined ? true : shared ;
436441 if ( _ . isFunction ( resolver ) ) {
437442 // Classes and factory functions alike: the legacy provider kind
438443 // annotate()s the resolver and calls or news it by casing.
439- this . container . register ( {
440- provide : name ,
444+ super . register ( {
445+ provide : nameOrProviders ,
441446 useLegacyClass : resolver ,
442447 shared,
443448 } ) ;
444449 } else {
445- this . container . register ( { provide : name , useValue : resolver , shared } ) ;
450+ super . register ( { provide : nameOrProviders , useValue : resolver , shared } ) ;
446451 }
447452 }
448453
@@ -452,7 +457,7 @@ export class Yok implements IInjector {
452457 public resolveCommand ( name : string ) : ICommand {
453458 let command : ICommand ;
454459 const commandModuleName = this . createCommandName ( name ) ;
455- if ( ! this . container . has ( commandModuleName ) ) {
460+ if ( ! this . has ( commandModuleName ) ) {
456461 return null ;
457462 }
458463 command = this . resolve ( commandModuleName ) ;
@@ -466,7 +471,7 @@ export class Yok implements IInjector {
466471 public resolveKeyCommand ( name : string ) : IKeyCommand {
467472 let command : IKeyCommand ;
468473 const commandModuleName = this . createKeyCommandName ( name ) ;
469- if ( ! this . container . has ( commandModuleName ) ) {
474+ if ( ! this . has ( commandModuleName ) ) {
470475 return null ;
471476 }
472477
@@ -483,9 +488,9 @@ export class Yok implements IInjector {
483488 if ( _ . isFunction ( param ) ) {
484489 // By-class resolution is transient and never retained — Yok did not
485490 // track these instances for disposal either.
486- return this . container . createInstance ( < Function > param , [ ] , ctorArguments ) ;
491+ return this . createInstance ( < Function > param , [ ] , ctorArguments ) ;
487492 }
488- return this . container . get ( < string > param , ctorArguments ) ;
493+ return this . get ( < string > param , ctorArguments ) ;
489494 }
490495
491496 /* Regex to match dynamic calls in the following format:
@@ -535,7 +540,7 @@ export class Yok implements IInjector {
535540 * and help, so the `|` encoding is user-visible.
536541 */
537542 public getRegisteredCommandsNames ( includeDev : boolean ) : string [ ] {
538- const commandsNames = this . container . getRegisteredNames (
543+ const commandsNames = this . getRegisteredNames (
539544 `${ this . COMMANDS_NAMESPACE } .` ,
540545 ) ;
541546 let commands = _ . map ( commandsNames , ( commandName : string ) =>
@@ -551,7 +556,7 @@ export class Yok implements IInjector {
551556 * @deprecated Legacy command-registry enumeration.
552557 */
553558 public getRegisteredKeyCommandsNames ( ) : string [ ] {
554- const commandsNames = this . container . getRegisteredNames (
559+ const commandsNames = this . getRegisteredNames (
555560 `${ this . KEY_COMMANDS_NAMESPACE } .` ,
556561 ) ;
557562 const commands = _ . map ( commandsNames , ( commandName : string ) =>
@@ -579,8 +584,8 @@ export class Yok implements IInjector {
579584 * @deprecated Delegates to Injector.dispose (reverse instantiation order);
580585 * new code disposes the di container directly.
581586 */
582- public dispose ( ) : void {
583- this . container . dispose ( [ this ] ) ;
587+ public dispose ( exclude : any [ ] = [ ] ) : void {
588+ super . dispose ( [ this , ... exclude ] ) ;
584589 }
585590}
586591
0 commit comments