Skip to content

Dependencies

reference
1 min readUpdated

Kind: Function

Source: packages/common/decorators/core/dependencies.decorator.ts

Part of: Common

Decorator that sets required dependencies (required with a vanilla JavaScript objects)

Dependencies is a class decorator that declares the dependencies required by a decorated component using a plain JavaScript object. It stores this dependency information as metadata so the surrounding framework can inspect, validate, or provide the required values during integration.

Signature

ts
function Dependencies(dependencies: Array<unknown>): ClassDecorator

Parameters

NameType
dependenciesArray<unknown>

Returns: ClassDecorator

Diagram

mermaid
graph LR
  A[Plain dependency object] --> B[@Dependencies]
  B --> C[Decorated class]
  C --> D[Dependency metadata]
  D --> E[Framework dependency resolution or validation]

Usage

ts
import { Dependencies } from '@your-package/common';

const logger = {
  info(message: string) {
    console.log(message);
  },
};

const configuration = {
  apiUrl: 'https://api.example.com',
};

@Dependencies({
  logger,
  configuration,
})
class ApiClient {
  fetchUsers() {
    logger.info(`Fetching users from ${configuration.apiUrl}`);
  }
}

const client = new ApiClient();
client.fetchUsers();

AI Coding Instructions

  • Pass dependencies as a plain JavaScript object, using clear property names for each required value.
  • Apply @Dependencies(...) to the class that needs the dependency metadata available to the framework.
  • Keep dependency definitions stable and avoid creating unrelated runtime state inside the decorator argument.
  • Ensure dependency keys match the names expected by the consuming resolver, validator, or integration layer.
  • When extending dependency handling, preserve the metadata contract used by other core decorators.

Used by

1 reference from 1 file. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

Imported by (1)

  • CatsControllersample/09-babel-example/src/cats/cats.controller.js:12

Was this page helpful?

Download as PDF
Dependencies — NestJS head-to-head