@Inject()

Resolves a provider by token when constructor type metadata is insufficient.

Since NestJS 10/11 Spec ↗

Syntax

@Inject(token: string | symbol | Type | Function)

Parameters

NameTypeRequiredDescription
token string | symbol | Type No The injection token identifying the provider to resolve.

Returns

ParameterDecorator — A decorator applied to a constructor parameter.

Examples

import { Injectable, Inject } from '@nestjs/common';

export const CONFIG = 'CONFIG_OPTIONS';

@Injectable()
export class MailService {
  constructor(@Inject(CONFIG) private readonly options: { apiKey: string }) {}
}

Notes

Use @Inject() with string or symbol tokens for custom providers, factory providers, or interfaces that have no runtime type. Class providers usually do not need it because their type metadata is enough.