docs/examples/dependency_injection/dependency_with_dependency_fn_and_default.py
raw| 1 | from typing import Any, Dict |
| 2 | |
| 3 | from litestar import Litestar, get |
| 4 | from litestar.di import NamedDependency |
| 5 | |
| 6 | |
| 7 | @get("/") |
| 8 | async def hello_world(optional_dependency: NamedDependency[int] = 3) -> Dict[str, Any]: |
| 9 | """Notice we haven't provided the dependency to the route. |
| 10 | |
| 11 | This is OK, because of the default value, and now the parameter is excluded from the docs. |
| 12 | """ |
| 13 | return {"hello": optional_dependency} |
| 14 | |
| 15 | |
| 16 | app = Litestar(route_handlers=[hello_world]) |