Parameter decorator that injects the value associated with the given token,
or undefined if the token is not registered in the container.
Throws an error if a circular dependency is detected. Use function injection with optionalBy if resolving circular dependencies is necessary.
Parameter decorator that injects the value associated with the given token,
or undefined if the token is not registered in the container.
This overload allows referencing a token declared later in the file by using the tokenRef helper function.
Throws an error if a circular dependency is detected. Use function injection with optionalBy if resolving circular dependencies is necessary.
Example:
class Wizard {
constructor(@Optional(tokenRef(() => Wand)) readonly wand: Wand | undefined) {}
}
// Other code...
class Wand {}
Parameter decorator that injects the instance associated with the given class, or
undefinedif the class is not registered in the container.Throws an error if a circular dependency is detected. Use function injection with optionalBy if resolving circular dependencies is necessary.