@lppedd/di-wise-neo 0.9.4 → 0.10.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.
@@ -155,7 +155,6 @@ interface ExistingProvider<Value> {
155
155
  type Provider<Value = any> = ClassProvider<Value & object> | FactoryProvider<Value> | ValueProvider<Value> | ExistingProvider<Value>;
156
156
 
157
157
  declare const Scope: {
158
- readonly Inherited: "Inherited";
159
158
  readonly Transient: "Transient";
160
159
  readonly Resolution: "Resolution";
161
160
  readonly Container: "Container";
@@ -203,7 +202,7 @@ interface ContainerOptions {
203
202
  /**
204
203
  * The default scope for registrations.
205
204
  *
206
- * @defaultValue Scope.Inherited
205
+ * @defaultValue Scope.Transient
207
206
  */
208
207
  readonly defaultScope: Scope;
209
208
  }
package/dist/es/index.mjs CHANGED
@@ -15,17 +15,17 @@ function throwUnregisteredError(token, name) {
15
15
  }
16
16
  // @internal
17
17
  function throwExistingUnregisteredError(token, cause) {
18
- const message = tag(`failed to resolve token ${getTokenName(token)}`);
19
- throw isError(cause) ? new Error(`${message}\n [cause] ${untag(cause.message)}`, {
18
+ const msg = tag(`failed to resolve token ${getTokenName(token)}`);
19
+ throw isError(cause) ? new Error(`${msg}\n [cause] ${untag(cause.message)}`, {
20
20
  cause
21
- }) : new Error(`${message}\n [cause] the aliased token ${getTokenName(cause)} is not registered`);
21
+ }) : new Error(`${msg}\n [cause] the aliased token ${getTokenName(cause)} is not registered`);
22
22
  }
23
23
  // @internal
24
24
  function throwParameterResolutionError(ctor, methodKey, dependency, cause) {
25
25
  const location = getLocation(ctor, methodKey);
26
26
  const tokenName = getTokenName(dependency.tokenRef.getRefToken());
27
- const message = tag(`failed to resolve dependency for ${location}(parameter #${dependency.index}: ${tokenName})`);
28
- throw new Error(`${message}\n [cause] ${untag(cause.message)}`, {
27
+ const msg = tag(`failed to resolve dependency for ${location}(parameter #${dependency.index}: ${tokenName})`);
28
+ throw new Error(`${msg}\n [cause] ${untag(cause.message)}`, {
29
29
  cause
30
30
  });
31
31
  }
@@ -296,7 +296,6 @@ function isExistingProvider(provider) {
296
296
  }
297
297
 
298
298
  const Scope = {
299
- Inherited: "Inherited",
300
299
  Transient: "Transient",
301
300
  Resolution: "Resolution",
302
301
  Container: "Container"
@@ -476,7 +475,7 @@ function isDisposable(value) {
476
475
  this.myParent = parent;
477
476
  this.myOptions = {
478
477
  autoRegister: false,
479
- defaultScope: Scope.Inherited,
478
+ defaultScope: Scope.Transient,
480
479
  ...options
481
480
  };
482
481
  this.myTokenRegistry = new TokenRegistry(this.myParent?.myTokenRegistry);
@@ -742,16 +741,15 @@ function isDisposable(value) {
742
741
  }
743
742
  const resolution = context.resolution;
744
743
  const provider = registration.provider;
745
- const options = registration.options;
746
744
  if (resolution.stack.has(provider)) {
747
745
  const dependentRef = resolution.dependents.get(provider);
748
746
  check(dependentRef, ()=>{
749
- const path = resolution.tokenStack.map(getTokenName).join(" → ");
750
- return `circular dependency detected while resolving ${path} → ${getTokenName(token)}`;
747
+ const path = resolution.tokenStack.map(getTokenName).concat(getTokenName(token)).join(" → ");
748
+ return `circular dependency detected while resolving ${path}`;
751
749
  });
752
750
  return dependentRef.current;
753
751
  }
754
- const scope = this.resolveScope(options?.scope, context);
752
+ const scope = registration.options?.scope ?? this.myOptions.defaultScope;
755
753
  const cleanups = [
756
754
  provideInjectionContext(context),
757
755
  resolution.tokenStack.push(token) && (()=>resolution.tokenStack.pop()),
@@ -798,13 +796,6 @@ function isDisposable(value) {
798
796
  cleanups.forEach((cleanup)=>cleanup && cleanup());
799
797
  }
800
798
  }
801
- resolveScope(scope = this.myOptions.defaultScope, context = useInjectionContext()) {
802
- if (scope === Scope.Inherited) {
803
- const dependentFrame = context?.resolution.stack.peek();
804
- return dependentFrame?.scope || Scope.Transient;
805
- }
806
- return scope;
807
- }
808
799
  resolveCtorDependencies(registration) {
809
800
  const dependencies = registration.dependencies;
810
801
  if (dependencies) {
@@ -882,7 +873,7 @@ function isDisposable(value) {
882
873
  * Creates a new container.
883
874
  */ function createContainer(options = {
884
875
  autoRegister: false,
885
- defaultScope: Scope.Inherited
876
+ defaultScope: Scope.Transient
886
877
  }) {
887
878
  return new ContainerImpl(undefined, options);
888
879
  }
@@ -1181,22 +1172,15 @@ function OptionalAll(token) {
1181
1172
  * ```
1182
1173
  */ const Injector = /*@__PURE__*/ build(()=>{
1183
1174
  const context = ensureInjectionContext("Injector factory");
1184
- const resolution = context.resolution;
1185
- const dependentFrame = resolution.stack.peek();
1186
- const dependentRef = dependentFrame && resolution.dependents.get(dependentFrame.provider);
1187
1175
  const runInContext = (fn)=>{
1188
1176
  if (useInjectionContext()) {
1189
1177
  return fn();
1190
1178
  }
1191
- const cleanups = [
1192
- provideInjectionContext(context),
1193
- dependentFrame && resolution.stack.push(dependentFrame.provider, dependentFrame),
1194
- dependentRef && resolution.dependents.set(dependentFrame.provider, dependentRef)
1195
- ];
1179
+ const cleanup = provideInjectionContext(context);
1196
1180
  try {
1197
1181
  return fn();
1198
1182
  } finally{
1199
- cleanups.forEach((cleanup)=>cleanup?.());
1183
+ cleanup();
1200
1184
  }
1201
1185
  };
1202
1186
  return {