---
lang: en
title: 'API docs: metadata.decoratorfactory'
keywords: LoopBack 4.0, LoopBack 4
sidebar: lb4_sidebar
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> 
```

## Constructors

|  Constructor | Modifiers | Description |
|  --- | --- | --- |
|  [(constructor)(key, spec, options)](./metadata.decoratorfactory.(constructor).md) |  | Construct a new class decorator factory |

## Properties

|  Property | Modifiers | Type | Description |
|  --- | --- | --- | --- |
|  [key](./metadata.decoratorfactory.key.md) |  | <code>string</code> |  |
|  [options](./metadata.decoratorfactory.options.md) |  | <code>DecoratorOptions &#124; undefined</code> |  |
|  [spec](./metadata.decoratorfactory.spec.md) |  | <code>T</code> |  |
|  [TARGET](./metadata.decoratorfactory.target.md) | <code>static</code> | <code>string</code> | 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 |
|  [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. For example:
```
class MyClass
MyClass.constructor[0] // First parameter of the constructor
MyClass.myStaticProperty
MyClass.myStaticMethod()
MyClass.myStaticMethod[0] // First parameter of the myStaticMethod
MyClass.prototype.myProperty
MyClass.prototype.myMethod()
MyClass.prototype.myMethod[1] // Second parameter of myMethod

```
 |
|  [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 |

## 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 {}

```


