Inject
function in meocord/decorator Since 4.1.0
Inject(
token: ProviderToken,
): (
target: object,
propertyKey: string | symbol | undefined,
parameterIndex: number,
) => voidInjects what a token provides into a constructor parameter.
Use it for a value provided under a string, a symbol or a createToken token, such as a database pool made
by a factory, or to inject a different class than the parameter's type. A parameter typed as a class is
injected by its type, and needs no decorator.
Parameters
| Name | Type | Description |
|---|---|---|
token | ProviderToken | The token a provider in |
Returns
Returns a parameter decorator.
(
target: object,
propertyKey: string | symbol | undefined,
parameterIndex: number,
) => voidExamples
const GREETING = createToken<string>('GREETING')
@Service()
export class Greeter {
constructor(@Inject(GREETING) private readonly greeting: string) {}
}