Skip to content

Annotated Provider

bevy.providers.annotated_provider.AnnotatedProvider

Bases: Provider[_A, _T]

The annotated provider supports typing.Annotated annotations. It will attempt to instantiate the annotated type if it's not found in the cache.

Example

@inject
def example(
    arg: Annotated[Dependency, "example-annotation"] = dependency()
):
    ...

factory

factory(key: _A, cache: _ProviderState[_A, _T]) -> Option[Callable[[], _T]]

Returns a callable that will get or construct an instance of the annotated type. If no instances exist in the repository matching the annotation, this will call the Repository.get method looking for the un-annotated type. That will attempt to instantiate an instance of the type if no providers have an instance cached.

supports

supports(key: _A, _) -> bool

Only allows the AnnotatedProvider to work with typing.Annotated wrapped types.