Skip to Content
GuidesOverview

Decorators Overview

redi provides parameter decorators to declare and configure dependencies. Here’s a quick reference.

Injection Decorators

Declare what dependencies should be injected. See Declare Dependency for details.

DecoratorDescription
@Inject(id)Inject a required dependency
@Optional(id?)Inject an optional dependency (returns null if not found)
@Many(id?)Inject all instances as an array

Lookup Decorators

Control where dependencies are resolved. See Hierarchy Injection for details.

DecoratorDescription
@Self()Only look in current injector
@SkipSelf()Skip current, look in parent
@InjectSelf()Inject the Injector itself

Behavior Decorators

Modify how dependencies are resolved.

DecoratorDescription
@WithNew()Create a new instance (skip singleton cache)

Most decorators can be combined. For example: @SkipSelf() @Optional(IConfig) looks for an optional dependency only in parent injectors.

Last updated on