Injectors
bevy.injectors.classes.Dependency
Dependency()
Bases: Generic[_K]
This class can be used to indicate fields that need to be injected. It also acts as a descriptor that can discover the key that needs to be injected and handle injecting the corresponding instance for that key when accessed.
To avoid typing errors that may arise from assigning instances of Dependency
to fields, use the dependency
function. That function returns a new instance of Dependency
but has a return type of typing.Any
.
bevy.injectors.classes.dependency
dependency() -> Any
This helper function allows instances of the Dependency
type to be assigned to fields without breaking type
checking.
bevy.injectors.functions.inject
inject(func: _C) -> Callable[_P, _R]
This decorator creates a wrapper function that scans the decorated function for dependencies. When the function is later called any dependency parameters that weren't passed in will be injected by the wrapper function. This can intelligently handle positional only arguments, positional arguments, named arguments, and keyword only arguments.
All parameters that should be injected need to be given a type hint that is supported by a provider and must have a
default value that is an instance of bevy.injectors.classes.Dependency
.