Page Contents
Home > @loopback/context > Binding > toInjectable
Binding.toInjectable() method
Bind to a class optionally decorated with @injectable
. Based on the introspection of the class, it calls toClass/toProvider/toDynamicValue
internally. The current binding key will be preserved (not being overridden by the key inferred from the class or options).
This is similar to createBindingFromClass() but applies to an existing binding.
Signature:
toInjectable(ctor: DynamicValueProviderClass<T> | Constructor<T | Provider<T>>): this;
Parameters
Parameter | Type | Description |
---|---|---|
ctor | DynamicValueProviderClass<T> | Constructor<T | Provider<T>> | A class decorated with @injectable . |
Returns:
this
Example
@injectable({scope: BindingScope.SINGLETON, tags: {service: 'MyService}})
class MyService {
// ...
}
const ctx = new Context();
ctx.bind('services.MyService').toInjectable(MyService);