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

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

[Home](./index.md) &gt; [@loopback/metadata](./metadata.md) &gt; [DecoratorFactory](./metadata.decoratorfactory.md)

## DecoratorFactory class

Base factory class for decorator functions

**Signature:**

```typescript
export declare class DecoratorFactory<T, // Type of the metadata spec for individual class/method/property/parameter
M extends T | MetadataMap<T> | MetadataMap<T[]>, // Type of the metadata
D extends DecoratorType> 
```

## Example


```
function classDecorator(spec: MySpec): ClassDecorator {
  return ClassDecoratorFactory.createDecorator('my-key', spec);
}
```
or

```
function classDecorator(spec: MySpec): ClassDecorator {
  const factory: ClassDecoratorFactory<MySpec>('my-key', spec);
  return factory.create();
}
```
These functions above declare `@classDecorator` that can be used as follows:

```
@classDecorator({x: 1})
class MyController {}
```

## Constructors

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

Constructor


</th><th>

Modifiers


</th><th>

Description


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

[(constructor)(key, spec, options)](./metadata.decoratorfactory._constructor_.md)


</td><td>


</td><td>

Construct a new class decorator factory


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

## Properties

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

Property


</th><th>

Modifiers


</th><th>

Type


</th><th>

Description


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

[decoratorName](./metadata.decoratorfactory.decoratorname.md)


</td><td>

`protected`


</td><td>

string


</td><td>


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

[key](./metadata.decoratorfactory.key.md)


</td><td>

`protected`


</td><td>

string


</td><td>


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

[options](./metadata.decoratorfactory.options.md)


</td><td>

`protected`


</td><td>

[DecoratorOptions](./metadata.decoratoroptions.md)


</td><td>


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

[spec](./metadata.decoratorfactory.spec.md)


</td><td>

`protected`


</td><td>

T


</td><td>


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

[TARGET](./metadata.decoratorfactory.target.md)


</td><td>

`static`


</td><td>

string


</td><td>

A constant to reference the target of a decoration


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

## Methods

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

Method


</th><th>

Modifiers


</th><th>

Description


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

[\_createDecorator(key, spec, options)](./metadata.decoratorfactory._createdecorator.md)


</td><td>

`protected`

`static`


</td><td>

Create a decorator function


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

[allowInheritance()](./metadata.decoratorfactory.allowinheritance.md)


</td><td>

`protected`


</td><td>


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

[cloneDeep(val)](./metadata.decoratorfactory.clonedeep.md)


</td><td>

`static`


</td><td>


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

[create()](./metadata.decoratorfactory.create.md)


</td><td>


</td><td>

Create a decorator function of the given type. Each sub class MUST implement this method.


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

[decorate(target, member, descriptorOrIndex)](./metadata.decoratorfactory.decorate.md)


</td><td>

`protected`


</td><td>

Base implementation of the decorator function


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

[duplicateDecorationError(target, member, descriptorOrIndex)](./metadata.decoratorfactory.duplicatedecorationerror.md)


</td><td>

`protected`


</td><td>

Create an error to report if the decorator is applied to the target more than once


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

[getNumberOfParameters(target, member)](./metadata.decoratorfactory.getnumberofparameters.md)


</td><td>

`static`


</td><td>

Get the number of parameters for a given constructor or method


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

[getTarget(spec)](./metadata.decoratorfactory.gettarget.md)


</td><td>


</td><td>

Get the optional decoration target of a given spec


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

[getTargetName(target, member, descriptorOrIndex)](./metadata.decoratorfactory.gettargetname.md)


</td><td>

`static`


</td><td>

Get the qualified name of a decoration target.


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

[inherit(inheritedMetadata)](./metadata.decoratorfactory.inherit.md)


</td><td>

`protected`


</td><td>

Inherit metadata from base classes. By default, this method merges base metadata into the spec if `allowInheritance` is set to `true`<!-- -->. To customize the behavior, this method can be overridden by sub classes.


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

[mergeWithInherited(inheritedMetadata, target, member, descriptorOrIndex)](./metadata.decoratorfactory.mergewithinherited.md)


</td><td>

`protected`


</td><td>

This method is called by the default implementation of the decorator function to merge the spec argument from the decoration with the inherited metadata for a class, all properties, all methods, or all method parameters that are decorated by this decorator.

It MUST be overridden by subclasses to process inherited metadata.


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

[mergeWithOwn(ownMetadata, target, member, descriptorOrIndex)](./metadata.decoratorfactory.mergewithown.md)


</td><td>

`protected`


</td><td>

This method is called by the default implementation of the decorator function to merge the spec argument from the decoration with the own metadata for a class, all properties, all methods, or all method parameters that are decorated by this decorator.

It MUST be overridden by subclasses to process own metadata.


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

[withTarget(spec, target)](./metadata.decoratorfactory.withtarget.md)


</td><td>


</td><td>

Set a reference to the target class or prototype for a given spec if it's an object


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


