Skip to content

PropertyDependency

reference
1 min readUpdated

Kind: Interface

Source: packages/core/injector/injector.ts

Part of: Core

The property-based dependency

PropertyDependency describes a dependency that should be injected into a property of a target instance. It stores the property key, the dependency metadata used to resolve the value, whether the dependency is optional, and the resolved instance value.

Properties

PropertyType
key`symbol
nameInjectorDependency
isOptionalboolean
instanceany

Diagram

mermaid
graph LR
  A[Target Instance] --> B[PropertyDependency]
  B --> C[key: string | symbol]
  B --> D[name: InjectorDependency]
  D --> E[Injector Resolution]
  E --> F[instance: resolved value]
  B --> G[isOptional]
  G --> H[Allow missing dependency]

Usage

ts
import type { PropertyDependency } from './injector';

const loggerDependency: PropertyDependency = {
  key: 'logger',
  name: {
    token: LoggerService,
  },
  isOptional: false,
  instance: undefined,
};

// During injection, the injector resolves `name` and assigns the result.
loggerDependency.instance = injector.get(loggerDependency.name.token);

targetInstance[loggerDependency.key] = loggerDependency.instance;

AI Coding Instructions

  • Use key as the exact property name or symbol that will receive the injected value.
  • Resolve dependencies through the injector using name; do not construct dependency instances directly.
  • Respect isOptional when resolution fails—optional dependencies should not throw injection errors.
  • Treat instance as the resolved runtime value and update it only after successful dependency resolution.
  • Preserve symbol keys when copying or applying property dependency metadata.

Was this page helpful?

Download as PDF
PropertyDependency — NestJS head-to-head