# PropertyDependency

**Kind:** Interface

**Source:** [`packages/core/injector/injector.ts`](https://github.com/nestjs/nest/blob/master/packages/core/injector/injector.ts#L56)

**Part of:** [Core](subsystem-packages-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

| Property | Type |
|---|---|
| `key` | `symbol | string` |
| `name` | `InjectorDependency` |
| `isOptional` | `boolean` |
| `instance` | `any` |

## 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.
