| 820 | ): Binding<ValueType> | undefined; |
| 821 | |
| 822 | getBinding<ValueType>( |
| 823 | key: BindingAddress<ValueType>, |
| 824 | options?: {optional?: boolean}, |
| 825 | ): Binding<ValueType> | undefined { |
| 826 | key = BindingKey.validate(key); |
| 827 | const binding = this.registry.get(key); |
| 828 | if (binding) { |
| 829 | return binding; |
| 830 | } |
| 831 | |
| 832 | if (this._parent) { |
| 833 | return this._parent.getBinding<ValueType>(key, options); |
| 834 | } |
| 835 | |
| 836 | if (options?.optional) return undefined; |
| 837 | throw new Error( |
| 838 | `The key '${key}' is not bound to any value in context ${this.name}`, |
| 839 | ); |
| 840 | } |
| 841 | |
| 842 | /** |
| 843 | * Find or create a binding for the given key |