* Bind the key to an instance of the given class. * * @param ctor - The class constructor to call. Any constructor * arguments must be annotated with `@inject` so that * we can resolve them from the context.
(ctor: Constructor<C>)
| 873 | * we can resolve them from the context. |
| 874 | */ |
| 875 | toClass<C extends T & object>(ctor: Constructor<C>): this { |
| 876 | /* istanbul ignore if */ |
| 877 | if (debug.enabled) { |
| 878 | debug('Bind %s to class %s', this.key, ctor.name); |
| 879 | } |
| 880 | this._source = { |
| 881 | type: BindingType.CLASS, |
| 882 | value: ctor, |
| 883 | }; |
| 884 | this._setValueGetter(resolutionCtx => { |
| 885 | const value = instantiateClass( |
| 886 | ctor, |
| 887 | resolutionCtx.context, |
| 888 | resolutionCtx.options.session, |
| 889 | ); |
| 890 | return Binding.valueOrProxy(resolutionCtx, value); |
| 891 | }); |
| 892 | return this; |
| 893 | } |
| 894 | |
| 895 | /** |
| 896 | * Bind to a class optionally decorated with `@injectable`. Based on the |