di

litestar.di.NamedDependency

Mark a parameter for name-based dependency injection.

The name of the function parameter will be used as the name for the dependency to inject.

alias of Annotated[T, <litestar.di.Dependency object at 0x7efc1dc719a0>]

class litestar.di.Provide[source]

Bases: object

Wrapper class for dependency injection

__init__(dependency: AnyCallable | type[Any], use_cache: bool = False, sync_to_thread: bool | None = None) None[source]

Initialize Provide

Parameters:
  • dependency – Callable to call or class to instantiate. The result is then injected as a dependency.

  • use_cache – Cache the dependency return value. Defaults to False.

  • sync_to_thread – Run sync code in an async thread. Defaults to False.

async __call__(**kwargs: Any) Any[source]

Call the provider’s dependency.