Debian Codegraph @

docs/examples/dependency_injection/dependency_non_optional_not_provided.py

raw
1 from typing import Any
2
3 from litestar import Litestar, get
4 from litestar.di import NamedDependency
5
6
7 @get("/")
8 async def hello_world(non_optional_dependency: NamedDependency[int]) -> dict[str, Any]:
9 """Notice we haven't provided the dependency to the route.
10
11 This is not great, however by explicitly marking dependencies, Litestar won't let the app start.
12 """
13 return {"hello": non_optional_dependency}
14
15
16 app = Litestar(route_handlers=[hello_world])
17
18 # ImproperlyConfiguredException: 500: Explicit dependency 'non_optional_dependency' for 'hello_world' has no default
19 # value, or provided dependency.