@@ -83,48 +83,48 @@ export class Container {
83
83
) : InstanceOf < T > {
84
84
this . resolutionContainer = resolutionContainer || new Container ( ) ;
85
85
86
- let cls = clsOrToken as TokenOrClass ;
86
+ try {
87
+ if ( this . resolutionSet . has ( clsOrToken ) ) {
88
+ throw new DependencyCycleError ( ) ;
89
+ }
87
90
88
- let scope : ScopeHandler ;
91
+ let cls = clsOrToken as TokenOrClass ;
89
92
90
- let container : Container = this ;
93
+ let scope : ScopeHandler ;
91
94
92
- const descriptor = this . getTokenDescriptor ( clsOrToken ) ;
95
+ let container : Container = this ;
93
96
94
- if ( ! descriptor ) {
95
- if ( clsOrToken instanceof Token ) {
96
- throw new TokenNotRegisteredError ( ) ;
97
- }
97
+ const descriptor = this . getTokenDescriptor ( clsOrToken ) ;
98
98
99
- cls = clsOrToken ;
99
+ this . resolutionSet . add ( clsOrToken ) ;
100
100
101
- scope = cls . scope || Scopes . Transient ( ) ;
101
+ if ( ! descriptor ) {
102
+ if ( clsOrToken instanceof Token ) {
103
+ throw new TokenNotRegisteredError ( ) ;
104
+ }
102
105
103
- container = this ;
104
- } else {
105
- if ( "class" in descriptor ) {
106
- cls = descriptor . class as ScopedClass ;
106
+ cls = clsOrToken ;
107
107
108
- scope = descriptor . scope || cls . scope || Scopes . Transient ( ) ;
108
+ scope = cls . scope || Scopes . Transient ( ) ;
109
109
110
- container = descriptor . container ;
111
- } else if ( "value" in descriptor ) {
112
- return descriptor . value ;
113
- } else if ( "factory" in descriptor ) {
114
- // @ts -ignore
115
- return descriptor . factory ( container , ...args ) ;
110
+ container = this ;
116
111
} else {
117
- throw new Error ( "Invalid descriptor" ) ;
118
- }
119
- }
120
-
121
- try {
122
- if ( this . resolutionSet . has ( clsOrToken ) ) {
123
- throw new DependencyCycleError ( ) ;
112
+ if ( "class" in descriptor ) {
113
+ cls = descriptor . class as ScopedClass ;
114
+
115
+ scope = descriptor . scope || cls . scope || Scopes . Transient ( ) ;
116
+
117
+ container = descriptor . container ;
118
+ } else if ( "value" in descriptor ) {
119
+ return descriptor . value ;
120
+ } else if ( "factory" in descriptor ) {
121
+ // @ts -ignore
122
+ return descriptor . factory ( container , ...args ) ;
123
+ } else {
124
+ throw new Error ( "Invalid descriptor" ) ;
125
+ }
124
126
}
125
127
126
- this . resolutionSet . add ( clsOrToken ) ;
127
-
128
128
return scope ( cls , args , container , this . resolutionContainer ) ;
129
129
} finally {
130
130
this . resolutionSet . delete ( clsOrToken ) ;
0 commit comments