---
lang: en
title: 'API docs: context.createbindingfromclass'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/strongloop/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()`

<b>Signature:</b>

```typescript
export declare function createBindingFromClass<T>(cls: Constructor<T | Provider<T>> | DynamicValueProviderClass<T>, options?: BindingFromClassOptions): Binding<T>;
```

## Parameters

|  Parameter | Type | Description |
|  --- | --- | --- |
|  cls | [Constructor](./context.constructor.md)<!-- -->&lt;T \| [Provider](./context.provider.md)<!-- -->&lt;T&gt;&gt; \| [DynamicValueProviderClass](./context.dynamicvalueproviderclass.md)<!-- -->&lt;T&gt; | A class. It can be either a plain class, a value provider class, or a dynamic value provider class |
|  options | [BindingFromClassOptions](./context.bindingfromclassoptions.md) | Options to customize the binding key |

<b>Returns:</b>

[Binding](./context.binding.md)<!-- -->&lt;T&gt;


