| 169 | * @typeParam T - Value type |
| 170 | */ |
| 171 | export function bindingTemplateFor<T>( |
| 172 | cls: Constructor<T | Provider<T>> | DynamicValueProviderClass<T>, |
| 173 | options?: BindingFromClassOptions, |
| 174 | ): BindingTemplate<T> { |
| 175 | const spec = getBindingMetadata(cls); |
| 176 | debug('class %s has binding metadata', cls.name, spec); |
| 177 | // Clone the templates array to avoid updating the cached metadata |
| 178 | const templateFunctions = [...(spec?.templates ?? [])]; |
| 179 | if (spec?.target !== cls) { |
| 180 | // Make sure the subclass is used as the binding source |
| 181 | templateFunctions.push(asClassOrProvider(cls) as BindingTemplate<unknown>); |
| 182 | } |
| 183 | return function applyBindingTemplatesFromMetadata(binding) { |
| 184 | for (const t of templateFunctions) { |
| 185 | binding.apply(t); |
| 186 | } |
| 187 | if (spec?.target !== cls) { |
| 188 | // Remove name/key tags inherited from base classes |
| 189 | binding.apply(removeNameAndKeyTags); |
| 190 | } |
| 191 | if (options != null) { |
| 192 | applyClassBindingOptions(binding, options); |
| 193 | } |
| 194 | }; |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Mapping artifact types to binding key namespaces (prefixes). |