22
submitted 3 weeks ago by lena@gregtech.eu to c/python@programming.dev
you are viewing a single comment's thread
view the rest of the comments
[-] joyjoy@lemmy.zip 1 points 2 weeks ago* (last edited 2 weeks ago)

As much as I've been disliking fastapi's direction recently, I can't abandon its annotation-based dependency injection. Having to reference injection's parameter name twice, and potentially decoupled from the route itself, does not sound like a fun time. It especially gets complicated with nested dependencies. You have to eagerly determine all the dependencies of your dependencies and provide them to either the route decorator or the app itself.

I would much rather do this

@get("/")
async def index(injection: Annotated[str, Provide(getThing)]): ...

Than what is currently required

@get("/", dependencies={"injection": Provide(getThing)})
async def index(injection: Annotated[str, Dependency()]): ...

litestar#2990 has shown they have no interest in this feature.

this post was submitted on 07 Aug 2025
22 points (95.8% liked)

Python

7406 readers
1 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

📅 Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
💓 Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 2 years ago
MODERATORS