* If the scope of current binding is `SINGLETON`, reset the context * to be the one that owns the current binding to make sure a singleton * does not have dependencies injected from child contexts unless the * injection is for method (excluding constructor) parameters.
( ctx: Context, injection: Readonly<Injection>, session?: ResolutionSession, )
| 94 | * injection is for method (excluding constructor) parameters. |
| 95 | */ |
| 96 | function resolveContext( |
| 97 | ctx: Context, |
| 98 | injection: Readonly<Injection>, |
| 99 | session?: ResolutionSession, |
| 100 | ) { |
| 101 | const currentBinding = session?.currentBinding; |
| 102 | if (currentBinding == null) { |
| 103 | // No current binding |
| 104 | return ctx; |
| 105 | } |
| 106 | |
| 107 | const isConstructorOrPropertyInjection = |
| 108 | // constructor injection |
| 109 | !injection.member || |
| 110 | // property injection |
| 111 | typeof injection.methodDescriptorOrParameterIndex !== 'number'; |
| 112 | |
| 113 | if (isConstructorOrPropertyInjection) { |
| 114 | // Set context to the resolution context of the current binding for |
| 115 | // constructor or property injections against a singleton |
| 116 | ctx = ctx.getResolutionContext(currentBinding)!; |
| 117 | } |
| 118 | return ctx; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Resolve the value or promise for a given injection |
no test coverage detected