---
lang: en
title: 'API docs: context.createbindingfromclass'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/context
permalink: /doc/en/lb4/apidocs.context.createbindingfromclass.html
---

<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@loopback/context](./context.md) &gt; [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)`<!-- -->: if `cls` is a value provider class with a prototype method `value()` - `binding.toDynamicValue(cls)`<!-- -->: if `cls` is a dynamic value provider class with a static method `value()`

**Signature:**

```typescript
export declare function createBindingFromClass<T>(cls: Constructor<T | Provider<T>> | DynamicValueProviderClass<T>, options?: BindingFromClassOptions): Binding<T>;
```

## Parameters

<table><thead><tr><th>

Parameter


</th><th>

Type


</th><th>

Description


</th></tr></thead>
<tbody><tr><td>

cls


</td><td>

[Constructor](./context.constructor.md)<!-- -->&lt;T \| [Provider](./context.provider.md)<!-- -->&lt;T&gt;&gt; \| [DynamicValueProviderClass](./context.dynamicvalueproviderclass.md)<!-- -->&lt;T&gt;


</td><td>

A class. It can be either a plain class, a value provider class, or a dynamic value provider class


</td></tr>
<tr><td>

options


</td><td>

[BindingFromClassOptions](./context.bindingfromclassoptions.md)


</td><td>

_(Optional)_ Options to customize the binding key


</td></tr>
</tbody></table>

**Returns:**

[Binding](./context.binding.md)<!-- -->&lt;T&gt;


