---
lang: en
title: 'API docs: metadata.decoratorfactory'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/strongloop/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

<b>Signature:</b>

```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

|  Constructor | Modifiers | Description |
|  --- | --- | --- |
|  [(constructor)(key, spec, options)](./metadata.decoratorfactory._constructor_.md) |  | Construct a new class decorator factory |

## Properties

|  Property | Modifiers | Type | Description |
|  --- | --- | --- | --- |
|  [decoratorName](./metadata.decoratorfactory.decoratorname.md) |  | string |  |
|  [key](./metadata.decoratorfactory.key.md) |  | string |  |
|  [options](./metadata.decoratorfactory.options.md) |  | [DecoratorOptions](./metadata.decoratoroptions.md) |  |
|  [spec](./metadata.decoratorfactory.spec.md) |  | T |  |
|  [TARGET](./metadata.decoratorfactory.target.md) | <code>static</code> | string | A constant to reference the target of a decoration |

## Methods

|  Method | Modifiers | Description |
|  --- | --- | --- |
|  [\_createDecorator(key, spec, options)](./metadata.decoratorfactory._createdecorator.md) | <code>static</code> | Create a decorator function |
|  [allowInheritance()](./metadata.decoratorfactory.allowinheritance.md) |  |  |
|  [cloneDeep(val)](./metadata.decoratorfactory.clonedeep.md) | <code>static</code> |  |
|  [create()](./metadata.decoratorfactory.create.md) |  | Create a decorator function of the given type. Each sub class MUST implement this method. |
|  [decorate(target, member, descriptorOrIndex)](./metadata.decoratorfactory.decorate.md) |  | Base implementation of the decorator function |
|  [duplicateDecorationError(target, member, descriptorOrIndex)](./metadata.decoratorfactory.duplicatedecorationerror.md) |  | Create an error to report if the decorator is applied to the target more than once |
|  [getNumberOfParameters(target, member)](./metadata.decoratorfactory.getnumberofparameters.md) | <code>static</code> | Get the number of parameters for a given constructor or method |
|  [getTarget(spec)](./metadata.decoratorfactory.gettarget.md) |  | Get the optional decoration target of a given spec |
|  [getTargetName(target, member, descriptorOrIndex)](./metadata.decoratorfactory.gettargetname.md) | <code>static</code> | Get the qualified name of a decoration target. |
|  [inherit(inheritedMetadata)](./metadata.decoratorfactory.inherit.md) |  | Inherit metadata from base classes. By default, this method merges base metadata into the spec if <code>allowInheritance</code> is set to <code>true</code>. To customize the behavior, this method can be overridden by sub classes. |
|  [mergeWithInherited(inheritedMetadata, target, member, descriptorOrIndex)](./metadata.decoratorfactory.mergewithinherited.md) |  | 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. |
|  [mergeWithOwn(ownMetadata, target, member, descriptorOrIndex)](./metadata.decoratorfactory.mergewithown.md) |  | 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. |
|  [withTarget(spec, target)](./metadata.decoratorfactory.withtarget.md) |  | Set a reference to the target class or prototype for a given spec if it's an object |


