* Locate and validate the resolution context * @param ctx - Current context * @param options - Resolution options
(ctx: Context, options: ResolutionOptions)
| 592 | * @param options - Resolution options |
| 593 | */ |
| 594 | private getResolutionContext(ctx: Context, options: ResolutionOptions) { |
| 595 | const resolutionCtx = ctx.getResolutionContext(this); |
| 596 | switch (this.scope) { |
| 597 | case BindingScope.APPLICATION: |
| 598 | case BindingScope.SERVER: |
| 599 | case BindingScope.REQUEST: |
| 600 | if (resolutionCtx == null) { |
| 601 | const msg = |
| 602 | `Binding "${this.key}" in context "${ctx.name}" cannot` + |
| 603 | ` be resolved in scope "${this.scope}"`; |
| 604 | if (options.optional) { |
| 605 | debug(msg); |
| 606 | return undefined; |
| 607 | } |
| 608 | throw new Error(msg); |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | const ownerCtx = ctx.getOwnerContext(this.key); |
| 613 | if (ownerCtx != null && !ownerCtx.isVisibleTo(resolutionCtx!)) { |
| 614 | const msg = |
| 615 | `Resolution context "${resolutionCtx?.name}" does not have ` + |
| 616 | `visibility to binding "${this.key} (scope:${this.scope})" in context "${ownerCtx.name}"`; |
| 617 | if (options.optional) { |
| 618 | debug(msg); |
| 619 | return undefined; |
| 620 | } |
| 621 | throw new Error(msg); |
| 622 | } |
| 623 | return resolutionCtx; |
| 624 | } |
| 625 | |
| 626 | /** |
| 627 | * Lock the binding so that it cannot be rebound |
no test coverage detected