@loopback/docs
Version:
Documentation for LoopBack 4
35 lines (22 loc) • 1.27 kB
Markdown
---
lang: en
title: 'API docs: context.createbindingfromclass'
keywords: LoopBack 4.0, LoopBack 4
sidebar: lb4_sidebar
permalink: /doc/en/lb4/apidocs.context.createbindingfromclass.html
---
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@loopback/context](./context.md) > [createBindingFromClass](./context.createbindingfromclass.md)
## createBindingFromClass() function
Create a binding from a class with decorated metadata. The class is attached to the binding as follows: - `binding.toClass(cls)`<!-- -->: if `cls` is a plain class such as `MyController` - `binding.toProvider(cls)`<!-- -->: it `cls` is a value provider class with a prototype method `value()`
<b>Signature:</b>
```typescript
export declare function createBindingFromClass<T = unknown>(cls: Constructor<T | Provider<T>>, options?: BindingFromClassOptions): Binding<T>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| cls | <code>Constructor<T | Provider<T>></code> | A class. It can be either a plain class or a value provider class |
| options | <code>BindingFromClassOptions</code> | Options to customize the binding key |
<b>Returns:</b>
`Binding<T>`