@lppedd/di-wise-neo 0.14.1 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -435,11 +435,11 @@ Normally, attempting to do that would result in a `ReferenceError`:
435
435
 
436
436
  > ReferenceError: Cannot access 'IStore' before initialization
437
437
 
438
- We can work around this problem by using the `forwardRef` helper function:
438
+ We can work around this problem by using the `tokenRef` helper function:
439
439
 
440
440
  ```ts
441
441
  export class ExtensionContext {
442
- constructor(@OptionalAll(forwardRef(() => IStore)) readonly stores: Store[]) {}
442
+ constructor(@OptionalAll(tokenRef(() => IStore)) readonly stores: Store[]) {}
443
443
 
444
444
  /* ... */
445
445
  }
@@ -119,6 +119,33 @@ declare function createType<T>(typeName: string): Type<T>;
119
119
  */
120
120
  declare function createType<T>(typeName: string, provider: Provider<T>, options?: RegistrationOptions): ProviderType<T>;
121
121
 
122
+ interface ClassRef<Instance extends object> {
123
+ readonly getRefClass: () => Constructor<Instance>;
124
+ }
125
+ interface TokensRef<Value = any> {
126
+ readonly getRefTokens: () => Set<Token<Value>>;
127
+ }
128
+ interface TokenRef<Value = any> {
129
+ readonly getRefToken: () => Token<Value>;
130
+ }
131
+ /**
132
+ * Allows referencing a class declared later in the file by wrapping it
133
+ * in a lazily evaluated function.
134
+ *
135
+ * @__NO_SIDE_EFFECTS__
136
+ */
137
+ declare function classRef<Instance extends object>(Class: () => Constructor<Instance>): ClassRef<Instance>;
138
+ /**
139
+ * Allows referencing tokens declared later in the file by wrapping them
140
+ * in a lazily evaluated function.
141
+ */
142
+ declare function tokenRef<Value>(token: () => Tokens<Value>): TokensRef<Value>;
143
+ /**
144
+ * Allows referencing a token declared later in the file by wrapping it
145
+ * in a lazily evaluated function.
146
+ */
147
+ declare function tokenRef<Value>(token: () => Token<Value>): TokenRef<Value>;
148
+
122
149
  /**
123
150
  * Provides a class instance for a token via a class constructor.
124
151
  */
@@ -126,7 +153,7 @@ interface ClassProvider<Instance extends object> {
126
153
  /**
127
154
  * The class to instantiate for the token.
128
155
  */
129
- readonly useClass: Constructor<Instance>;
156
+ readonly useClass: Constructor<Instance> | ClassRef<Instance>;
130
157
  /**
131
158
  * An optional name to qualify this provider.
132
159
  * If specified, the token must be resolved using the same name.
@@ -597,47 +624,39 @@ declare function AutoRegister(): ClassDecorator;
597
624
  */
598
625
  declare function EagerInstantiate(): ClassDecorator;
599
626
 
600
- interface TokensRef<Value = any> {
601
- readonly getRefTokens: () => Set<Token<Value>>;
602
- }
603
- interface TokenRef<Value = any> {
604
- readonly getRefToken: () => Token<Value>;
605
- }
606
- /**
607
- * Allows referencing tokens declared later in the file by wrapping them
608
- * in a lazily evaluated function.
609
- */
610
- declare function forwardRef<Value>(token: () => Tokens<Value>): TokensRef<Value>;
611
- /**
612
- * Allows referencing a token declared later in the file by wrapping it
613
- * in a lazily evaluated function.
614
- */
615
- declare function forwardRef<Value>(token: () => Token<Value>): TokenRef<Value>;
616
-
617
627
  /**
618
628
  * Parameter decorator that injects the instance associated with the given class.
619
629
  *
620
- * Throws an error if the class is not registered in the container.
630
+ * Throws an error if:
631
+ * - The class is not registered in the container.
632
+ * - A circular dependency is detected. Use function injection with {@link injectBy}
633
+ * if resolving circular dependencies is necessary.
621
634
  */
622
635
  declare function Inject<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;
623
636
  /**
624
637
  * Parameter decorator that injects the value associated with the given token.
625
638
  *
626
- * Throws an error if the token is not registered in the container.
639
+ * Throws an error if:
640
+ * - The token is not registered in the container.
641
+ * - A circular dependency is detected. Use function injection with {@link injectBy}
642
+ * if resolving circular dependencies is necessary.
627
643
  */
628
644
  declare function Inject<Value>(token: Token<Value>): ParameterDecorator;
629
645
  /**
630
646
  * Parameter decorator that injects the value associated with the given token.
631
647
  *
632
648
  * Allows referencing a token declared later in the file by using the
633
- * {@link forwardRef} helper function.
649
+ * {@link tokenRef} helper function.
634
650
  *
635
- * Throws an error if the token is not registered in the container.
651
+ * Throws an error if:
652
+ * - The token is not registered in the container.
653
+ * - A circular dependency is detected. Use function injection with {@link injectBy}
654
+ * if resolving circular dependencies is necessary.
636
655
  *
637
656
  * @example
638
657
  * ```ts
639
658
  * class Wizard {
640
- * constructor(@Inject(forwardRef(() => Wand)) readonly wand: Wand) {}
659
+ * constructor(@Inject(tokenRef(() => Wand)) readonly wand: Wand) {}
641
660
  * }
642
661
  * // Other code...
643
662
  * class Wand {}
@@ -665,11 +684,11 @@ declare function Injectable<This extends object, Value extends This>(...tokens:
665
684
  * The container uses {@link ExistingProvider} under the hood.
666
685
  *
667
686
  * Allows referencing tokens that are declared later in the file by using
668
- * the {@link forwardRef} helper function.
687
+ * the {@link tokenRef} helper function.
669
688
  *
670
689
  * @example
671
690
  * ```ts
672
- * @Injectable(forwardRef() => Weapon) // Weapon is declared after Wand
691
+ * @Injectable(tokenRef() => Weapon) // Weapon is declared after Wand
673
692
  * class Wizard {}
674
693
  * // Other code...
675
694
  * class Weapon {}
@@ -681,14 +700,18 @@ declare function Injectable<This extends object, Value extends This>(tokens: Tok
681
700
  * Parameter decorator that injects all instances provided by the registrations
682
701
  * associated with the given class.
683
702
  *
684
- * Throws an error if the class is not registered in the container.
703
+ * Throws an error if:
704
+ * - The class is not registered in the container.
705
+ * - A circular dependency is detected.
685
706
  */
686
707
  declare function InjectAll<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;
687
708
  /**
688
709
  * Parameter decorator that injects all values provided by the registrations
689
710
  * associated with the given token.
690
711
  *
691
- * Throws an error if the token is not registered in the container.
712
+ * Throws an error if:
713
+ * - The token is not registered in the container.
714
+ * - A circular dependency is detected.
692
715
  */
693
716
  declare function InjectAll<Value>(token: Token<Value>): ParameterDecorator;
694
717
  /**
@@ -696,14 +719,16 @@ declare function InjectAll<Value>(token: Token<Value>): ParameterDecorator;
696
719
  * associated with the given token.
697
720
  *
698
721
  * Allows referencing a token declared later in the file by using the
699
- * {@link forwardRef} helper function.
722
+ * {@link tokenRef} helper function.
700
723
  *
701
- * Throws an error if the token is not registered in the container.
724
+ * Throws an error if:
725
+ * - The token is not registered in the container.
726
+ * - A circular dependency is detected.
702
727
  *
703
728
  * @example
704
729
  * ```ts
705
730
  * class Wizard {
706
- * constructor(@InjectAll(forwardRef(() => Wand)) readonly wands: Wand[]) {}
731
+ * constructor(@InjectAll(tokenRef(() => Wand)) readonly wands: Wand[]) {}
707
732
  * }
708
733
  * // Other code...
709
734
  * class Wand {}
@@ -734,11 +759,17 @@ declare function Named(name: string): ClassDecorator & ParameterDecorator;
734
759
  /**
735
760
  * Parameter decorator that injects the instance associated with the given class,
736
761
  * or `undefined` if the class is not registered in the container.
762
+ *
763
+ * Throws an error if a circular dependency is detected. Use function injection
764
+ * with {@link optionalBy} if resolving circular dependencies is necessary.
737
765
  */
738
766
  declare function Optional<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;
739
767
  /**
740
768
  * Parameter decorator that injects the value associated with the given token,
741
769
  * or `undefined` if the token is not registered in the container.
770
+ *
771
+ * Throws an error if a circular dependency is detected. Use function injection
772
+ * with {@link optionalBy} if resolving circular dependencies is necessary.
742
773
  */
743
774
  declare function Optional<Value>(token: Token<Value>): ParameterDecorator;
744
775
  /**
@@ -746,12 +777,15 @@ declare function Optional<Value>(token: Token<Value>): ParameterDecorator;
746
777
  * or `undefined` if the token is not registered in the container.
747
778
  *
748
779
  * Allows referencing a token declared later in the file by using the
749
- * {@link forwardRef} helper function.
780
+ * {@link tokenRef} helper function.
781
+ *
782
+ * Throws an error if a circular dependency is detected. Use function injection
783
+ * with {@link optionalBy} if resolving circular dependencies is necessary.
750
784
  *
751
785
  * @example
752
786
  * ```ts
753
787
  * class Wizard {
754
- * constructor(@Optional(forwardRef(() => Wand)) readonly wand: Wand | undefined) {}
788
+ * constructor(@Optional(tokenRef(() => Wand)) readonly wand: Wand | undefined) {}
755
789
  * }
756
790
  * // Other code...
757
791
  * class Wand {}
@@ -763,12 +797,16 @@ declare function Optional<Value>(tokens: TokenRef<Value>): ParameterDecorator;
763
797
  * Parameter decorator that injects all instances provided by the registrations
764
798
  * associated with the given class or an empty array if the class is not registered
765
799
  * in the container.
800
+ *
801
+ * Throws an error if a circular dependency is detected.
766
802
  */
767
803
  declare function OptionalAll<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;
768
804
  /**
769
805
  * Parameter decorator that injects all values provided by the registrations
770
806
  * associated with the given token or an empty array if the token is not registered
771
807
  * in the container.
808
+ *
809
+ * Throws an error if a circular dependency is detected.
772
810
  */
773
811
  declare function OptionalAll<Value>(token: Token<Value>): ParameterDecorator;
774
812
  /**
@@ -777,12 +815,14 @@ declare function OptionalAll<Value>(token: Token<Value>): ParameterDecorator;
777
815
  * in the container.
778
816
  *
779
817
  * Allows referencing a token declared later in the file by using the
780
- * {@link forwardRef} helper function.
818
+ * {@link tokenRef} helper function.
819
+ *
820
+ * Throws an error if a circular dependency is detected.
781
821
  *
782
822
  * @example
783
823
  * ```ts
784
824
  * class Wizard {
785
- * constructor(@OptionalAll(forwardRef(() => Wand)) readonly wands: Wand[]) {}
825
+ * constructor(@OptionalAll(tokenRef(() => Wand)) readonly wands: Wand[]) {}
786
826
  * }
787
827
  * // Other code...
788
828
  * class Wand {}
@@ -817,13 +857,19 @@ declare function Scoped(scope: Scope): ClassDecorator;
817
857
  /**
818
858
  * Injects the instance associated with the given class.
819
859
  *
820
- * Throws an error if the class is not registered in the container.
860
+ * Throws an error if:
861
+ * - The class is not registered in the container.
862
+ * - A circular dependency is detected. Use {@link injectBy} if resolving
863
+ * circular dependencies is necessary.
821
864
  */
822
865
  declare function inject<Instance extends object>(Class: Constructor<Instance>, name?: string): Instance;
823
866
  /**
824
867
  * Injects the value associated with the given token.
825
868
  *
826
- * Throws an error if the token is not registered in the container.
869
+ * Throws an error if:
870
+ * - The token is not registered in the container.
871
+ * - A circular dependency is detected. Use {@link injectBy} if resolving
872
+ * circular dependencies is necessary.
827
873
  */
828
874
  declare function inject<Value>(token: Token<Value>, name?: string): Value;
829
875
  /**
@@ -832,7 +878,7 @@ declare function inject<Value>(token: Token<Value>, name?: string): Value;
832
878
  * Throws an error if the class is not registered in the container.
833
879
  *
834
880
  * Compared to {@link inject}, `injectBy` accepts a `thisArg` argument
835
- * (the containing class) which is used to resolve circular dependencies.
881
+ * (e.g., the containing class instance) which is used to resolve circular dependencies.
836
882
  *
837
883
  * @example
838
884
  * ```ts
@@ -856,7 +902,7 @@ declare function injectBy<Instance extends object>(thisArg: any, Class: Construc
856
902
  * Throws an error if the token is not registered in the container.
857
903
  *
858
904
  * Compared to {@link inject}, `injectBy` accepts a `thisArg` argument
859
- * (the containing class) which is used to resolve circular dependencies.
905
+ * (e.g., the containing class instance) which is used to resolve circular dependencies.
860
906
  *
861
907
  * @example
862
908
  * ```ts
@@ -878,13 +924,17 @@ declare function injectBy<Value>(thisArg: any, token: Token<Value>, name?: strin
878
924
  /**
879
925
  * Injects all instances provided by the registrations associated with the given class.
880
926
  *
881
- * Throws an error if the class is not registered in the container.
927
+ * Throws an error if:
928
+ * - The class is not registered in the container.
929
+ * - A circular dependency is detected.
882
930
  */
883
931
  declare function injectAll<Instance extends object>(Class: Constructor<Instance>): Instance[];
884
932
  /**
885
933
  * Injects all values provided by the registrations associated with the given token.
886
934
  *
887
- * Throws an error if the token is not registered in the container.
935
+ * Throws an error if:
936
+ * - The token is not registered in the container.
937
+ * - A circular dependency is detected.
888
938
  */
889
939
  declare function injectAll<Value>(token: Token<Value>): Value[];
890
940
 
@@ -1044,11 +1094,17 @@ declare function applyMiddleware(container: Container, middlewares: Middleware[]
1044
1094
  /**
1045
1095
  * Injects the instance associated with the given class,
1046
1096
  * or `undefined` if the class is not registered in the container.
1097
+ *
1098
+ * Throws an error if a circular dependency is detected.
1099
+ * Use {@link optionalBy} if resolving circular dependencies is necessary.
1047
1100
  */
1048
1101
  declare function optional<Instance extends object>(Class: Constructor<Instance>, name?: string): Instance | undefined;
1049
1102
  /**
1050
1103
  * Injects the value associated with the given token,
1051
1104
  * or `undefined` if the token is not registered in the container.
1105
+ *
1106
+ * Throws an error if a circular dependency is detected.
1107
+ * Use {@link optionalBy} if resolving circular dependencies is necessary.
1052
1108
  */
1053
1109
  declare function optional<Value>(token: Token<Value>, name?: string): Value | undefined;
1054
1110
  /**
@@ -1056,7 +1112,7 @@ declare function optional<Value>(token: Token<Value>, name?: string): Value | un
1056
1112
  * or `undefined` if the class is not registered in the container.
1057
1113
  *
1058
1114
  * Compared to {@link optional}, `optionalBy` accepts a `thisArg` argument
1059
- * (the containing class) which is used to resolve circular dependencies.
1115
+ * (e.g., the containing class instance) which is used to resolve circular dependencies.
1060
1116
  *
1061
1117
  * @param thisArg - The containing instance, used to help resolve circular dependencies.
1062
1118
  * @param Class - The class to resolve.
@@ -1068,7 +1124,7 @@ declare function optionalBy<Instance extends object>(thisArg: any, Class: Constr
1068
1124
  * or `undefined` if the token is not registered in the container.
1069
1125
  *
1070
1126
  * Compared to {@link optional}, `optionalBy` accepts a `thisArg` argument
1071
- * (the containing class) which is used to resolve circular dependencies.
1127
+ * (e.g., the containing class instance) which is used to resolve circular dependencies.
1072
1128
  *
1073
1129
  * @param thisArg - The containing instance, used to help resolve circular dependencies.
1074
1130
  * @param token - The token to resolve.
@@ -1079,13 +1135,17 @@ declare function optionalBy<Value>(thisArg: any, token: Token<Value>, name?: str
1079
1135
  /**
1080
1136
  * Injects all instances provided by the registrations associated with the given class
1081
1137
  * or an empty array if the class is not registered in the container.
1138
+ *
1139
+ * Throws an error if a circular dependency is detected.
1082
1140
  */
1083
1141
  declare function optionalAll<Instance extends object>(Class: Constructor<Instance>): Instance[];
1084
1142
  /**
1085
1143
  * Injects all values provided by the registrations associated with the given token
1086
1144
  * or an empty array if the token is not registered in the container.
1145
+ *
1146
+ * Throws an error if a circular dependency is detected.
1087
1147
  */
1088
1148
  declare function optionalAll<Value>(token: Token<Value>): Value[];
1089
1149
 
1090
- export { AutoRegister, EagerInstantiate, Inject, InjectAll, Injectable, Injector, Named, Optional, OptionalAll, Scope, Scoped, applyMiddleware, build, createContainer, createType, forwardRef, inject, injectAll, injectBy, optional, optionalAll, optionalBy, setClassIdentityMapping };
1091
- export type { ClassProvider, Constructor, Container, ContainerOptions, ExistingProvider, FactoryProvider, Middleware, MiddlewareComposer, Provider, ProviderType, RegistrationOptions, Token, TokenRef, Tokens, TokensRef, Type, ValueProvider };
1150
+ export { AutoRegister, EagerInstantiate, Inject, InjectAll, Injectable, Injector, Named, Optional, OptionalAll, Scope, Scoped, applyMiddleware, build, classRef, createContainer, createType, inject, injectAll, injectBy, optional, optionalAll, optionalBy, setClassIdentityMapping, tokenRef };
1151
+ export type { ClassProvider, ClassRef, Constructor, Container, ContainerOptions, ExistingProvider, FactoryProvider, Middleware, MiddlewareComposer, Provider, ProviderType, RegistrationOptions, Token, TokenRef, Tokens, TokensRef, Type, ValueProvider };
package/dist/cjs/index.js CHANGED
@@ -186,6 +186,47 @@ function injectAll(token) {
186
186
  return context.container.resolveAll(token);
187
187
  }
188
188
 
189
+ /**
190
+ * Allows referencing a class declared later in the file by wrapping it
191
+ * in a lazily evaluated function.
192
+ *
193
+ * @__NO_SIDE_EFFECTS__
194
+ */ function classRef(Class) {
195
+ return {
196
+ getRefClass: ()=>Class()
197
+ };
198
+ }
199
+ // @__NO_SIDE_EFFECTS__
200
+ function tokenRef(token) {
201
+ return {
202
+ getRefTokens: ()=>{
203
+ // Normalize the single token here so that we don't have to do it at every getRefTokens call site
204
+ const tokenOrTokens = token();
205
+ const tokensArray = Array.isArray(tokenOrTokens) ? tokenOrTokens : [
206
+ tokenOrTokens
207
+ ];
208
+ return new Set(tokensArray);
209
+ },
210
+ getRefToken: ()=>{
211
+ const tokenOrTokens = token();
212
+ check(!Array.isArray(tokenOrTokens), "internal error: ref tokens should be a single token");
213
+ return tokenOrTokens;
214
+ }
215
+ };
216
+ }
217
+ // @internal
218
+ function isClassRef(value) {
219
+ return value && typeof value === "object" && typeof value.getRefClass === "function";
220
+ }
221
+ // @internal
222
+ function isTokensRef(value) {
223
+ return value && typeof value === "object" && typeof value.getRefTokens === "function";
224
+ }
225
+ // @internal
226
+ function isTokenRef(value) {
227
+ return value && typeof value === "object" && typeof value.getRefToken === "function";
228
+ }
229
+
189
230
  // @internal
190
231
  class Metadata {
191
232
  constructor(Class){
@@ -234,7 +275,8 @@ class Metadata {
234
275
  }
235
276
  }
236
277
  // @internal
237
- function getMetadata(Class) {
278
+ function getMetadata(classOrRef) {
279
+ const Class = isClassRef(classOrRef) ? classOrRef.getRefClass() : classOrRef;
238
280
  const originalClass = classIdentityMap.get(Class) ?? Class;
239
281
  let metadata = metadataMap.get(originalClass);
240
282
  if (!metadata) {
@@ -337,7 +379,6 @@ const Scope = {
337
379
  */ Container: "Container"
338
380
  };
339
381
 
340
- // @internal
341
382
  // @__NO_SIDE_EFFECTS__
342
383
  function createType(typeName, provider, options) {
343
384
  const name = `Type<${typeName}>`;
@@ -1008,32 +1049,6 @@ function isDisposable(value) {
1008
1049
  };
1009
1050
  }
1010
1051
 
1011
- function forwardRef(token) {
1012
- return {
1013
- getRefTokens: ()=>{
1014
- // Normalize the single token here so that we don't have to do it at every getRefTokens call site
1015
- const tokenOrTokens = token();
1016
- const tokensArray = Array.isArray(tokenOrTokens) ? tokenOrTokens : [
1017
- tokenOrTokens
1018
- ];
1019
- return new Set(tokensArray);
1020
- },
1021
- getRefToken: ()=>{
1022
- const tokenOrTokens = token();
1023
- check(!Array.isArray(tokenOrTokens), "internal error: ref tokens should be a single token");
1024
- return tokenOrTokens;
1025
- }
1026
- };
1027
- }
1028
- // @internal
1029
- function isTokensRef(value) {
1030
- return value && typeof value === "object" && typeof value.getRefTokens === "function";
1031
- }
1032
- // @internal
1033
- function isTokenRef(value) {
1034
- return value && typeof value === "object" && typeof value.getRefToken === "function";
1035
- }
1036
-
1037
1052
  // @internal
1038
1053
  function updateParameterMetadata(decorator, target, methodKey, parameterIndex, updateFn) {
1039
1054
  // Error out immediately if the decorator has been applied to a static method
@@ -1083,23 +1098,23 @@ function describeParam(target, methodKey, parameterIndex) {
1083
1098
  return `${location}(parameter #${parameterIndex})`;
1084
1099
  }
1085
1100
 
1101
+ // @__NO_SIDE_EFFECTS__
1086
1102
  function Inject(token) {
1087
1103
  return function(target, propertyKey, parameterIndex) {
1088
1104
  updateParameterMetadata("Inject", target, propertyKey, parameterIndex, (dependency)=>{
1089
1105
  checkSingleDecorator(dependency, target, propertyKey, parameterIndex);
1090
1106
  dependency.appliedBy = "Inject";
1091
- dependency.tokenRef = isTokenRef(token) ? token : forwardRef(()=>token);
1107
+ dependency.tokenRef = isTokenRef(token) ? token : tokenRef(()=>token);
1092
1108
  });
1093
1109
  };
1094
1110
  }
1095
1111
 
1096
- /**
1097
- * @__NO_SIDE_EFFECTS__
1098
- */ function Injectable(...args) {
1112
+ // @__NO_SIDE_EFFECTS__
1113
+ function Injectable(...args) {
1099
1114
  return function(Class) {
1100
1115
  const metadata = getMetadata(Class);
1101
1116
  const arg0 = args[0];
1102
- const tokensRef = isTokensRef(arg0) ? arg0 : forwardRef(()=>args);
1117
+ const tokensRef = isTokensRef(arg0) ? arg0 : tokenRef(()=>args);
1103
1118
  const existingTokensRef = metadata.tokensRef;
1104
1119
  metadata.tokensRef = {
1105
1120
  getRefTokens: ()=>{
@@ -1113,12 +1128,13 @@ function Inject(token) {
1113
1128
  };
1114
1129
  }
1115
1130
 
1131
+ // @__NO_SIDE_EFFECTS__
1116
1132
  function InjectAll(token) {
1117
1133
  return function(target, propertyKey, parameterIndex) {
1118
1134
  updateParameterMetadata("InjectAll", target, propertyKey, parameterIndex, (dependency)=>{
1119
1135
  checkSingleDecorator(dependency, target, propertyKey, parameterIndex);
1120
1136
  dependency.appliedBy = "InjectAll";
1121
- dependency.tokenRef = isTokenRef(token) ? token : forwardRef(()=>token);
1137
+ dependency.tokenRef = isTokenRef(token) ? token : tokenRef(()=>token);
1122
1138
  checkNamedDecorator(dependency, target, propertyKey, parameterIndex);
1123
1139
  });
1124
1140
  };
@@ -1165,22 +1181,24 @@ function InjectAll(token) {
1165
1181
  };
1166
1182
  }
1167
1183
 
1184
+ // @__NO_SIDE_EFFECTS__
1168
1185
  function Optional(token) {
1169
1186
  return function(target, propertyKey, parameterIndex) {
1170
1187
  updateParameterMetadata("Optional", target, propertyKey, parameterIndex, (dependency)=>{
1171
1188
  checkSingleDecorator(dependency, target, propertyKey, parameterIndex);
1172
1189
  dependency.appliedBy = "Optional";
1173
- dependency.tokenRef = isTokenRef(token) ? token : forwardRef(()=>token);
1190
+ dependency.tokenRef = isTokenRef(token) ? token : tokenRef(()=>token);
1174
1191
  });
1175
1192
  };
1176
1193
  }
1177
1194
 
1195
+ // @__NO_SIDE_EFFECTS__
1178
1196
  function OptionalAll(token) {
1179
1197
  return function(target, propertyKey, parameterIndex) {
1180
1198
  updateParameterMetadata("OptionalAll", target, propertyKey, parameterIndex, (dependency)=>{
1181
1199
  checkSingleDecorator(dependency, target, propertyKey, parameterIndex);
1182
1200
  dependency.appliedBy = "OptionalAll";
1183
- dependency.tokenRef = isTokenRef(token) ? token : forwardRef(()=>token);
1201
+ dependency.tokenRef = isTokenRef(token) ? token : tokenRef(()=>token);
1184
1202
  checkNamedDecorator(dependency, target, propertyKey, parameterIndex);
1185
1203
  });
1186
1204
  };
@@ -1318,9 +1336,9 @@ exports.Scope = Scope;
1318
1336
  exports.Scoped = Scoped;
1319
1337
  exports.applyMiddleware = applyMiddleware;
1320
1338
  exports.build = build;
1339
+ exports.classRef = classRef;
1321
1340
  exports.createContainer = createContainer;
1322
1341
  exports.createType = createType;
1323
- exports.forwardRef = forwardRef;
1324
1342
  exports.inject = inject;
1325
1343
  exports.injectAll = injectAll;
1326
1344
  exports.injectBy = injectBy;
@@ -1328,4 +1346,5 @@ exports.optional = optional;
1328
1346
  exports.optionalAll = optionalAll;
1329
1347
  exports.optionalBy = optionalBy;
1330
1348
  exports.setClassIdentityMapping = setClassIdentityMapping;
1349
+ exports.tokenRef = tokenRef;
1331
1350
  //# sourceMappingURL=index.js.map