Skip to content

Commit

Permalink
refactor: rename variable
Browse files Browse the repository at this point in the history
  • Loading branch information
exuanbo committed Oct 23, 2024
1 parent 580d5a6 commit 53b0fe1
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,10 @@ export class Container {
private construct<T extends object>(Class: Constructor<T>): T {
const metadata = getMetadata(Class);
const provider = metadata.provider;
const resolvedScope = this.resolveScope(metadata.scope);
if (resolvedScope == Scope.Container) {
const options = {scope: this.resolveScope(metadata.scope)};
if (options.scope == Scope.Container) {
throw new Error(`unregistered token ${Class.name} cannot be resolved in container scope`);
}
const options = {scope: resolvedScope};
return this.getScopedInstance({provider, options}, () => new Class());
}

Expand Down Expand Up @@ -194,14 +193,11 @@ export class Container {
return dependentRef.current;
}

const resolvedScope = this.resolveScope(options?.scope);
const scope = this.resolveScope(options?.scope);

context.resolution.stack.push(provider, {
provider,
scope: resolvedScope,
});
context.resolution.stack.push(provider, {provider, scope});
try {
if (resolvedScope == Scope.Container) {
if (scope == Scope.Container) {
const instanceRef = registration.instance;
if (instanceRef) {
return instanceRef.current;
Expand All @@ -210,7 +206,7 @@ export class Container {
registration.instance = {current: instance};
return instance;
}
if (resolvedScope == Scope.Resolution) {
if (scope == Scope.Resolution) {
const instanceRef = context.resolution.instances.get(provider);
if (instanceRef) {
return instanceRef.current;
Expand All @@ -219,10 +215,10 @@ export class Container {
context.resolution.instances.set(provider, {current: instance});
return instance;
}
if (resolvedScope == Scope.Transient) {
if (scope == Scope.Transient) {
return instantiate();
}
expectNever(resolvedScope);
expectNever(scope);
}
finally {
context.resolution.stack.pop();
Expand Down

0 comments on commit 53b0fe1

Please sign in to comment.