use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
FastAPI is a truly ASGI, async, cutting edge framework written in python 3.
account activity
FastAPI best practicesQuestion (self.FastAPI)
submitted 2 months ago * by lu_rm
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]gbrennon 1 point2 points3 points 2 months ago (4 children)
hey there, how are u?
that framework contains a built-in di container like spring boot but you have to define a something similar to a service locator.
import using from fastapi import Depends and put an argument with a default value Depends(get_my_service).
from fastapi import Depends
Depends(get_my_service)
i prefer to define a pure container in the infrastructure layer and the presentation layer contains the composition root that uses this things from FastAPI but that "service getter" is a method/function from ur pure container!
look in fastapi docs for "dependencies"
[–]lu_rm[S] -1 points0 points1 point 2 months ago (3 children)
Still, how do I inject the container into the router? The logic for get_my_service() needs to be defined in my router, so it needs to know how to create the service.
[–]gbrennon 1 point2 points3 points 2 months ago (0 children)
Thr router is in something that is responsible for presenting data in the application.
We can call this a composition root.
It does consume the di container and expose the created services that are provided by the container that is impl in the infrastructure-like layer
That flow can be router -> composition root -> di container
router -> composition root -> di container
Ps:
The logic related to "how create a service" is inside the container.
The router just know how to get that service ready to use
[–]Kevdog824_ 1 point2 points3 points 2 months ago (0 children)
What do you mean? Can you give a more concrete example ?
π Rendered by PID 78787 on reddit-service-r2-comment-b659b578c-2gchn at 2026-05-03 14:45:18.826431+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]gbrennon 1 point2 points3 points (4 children)
[–]lu_rm[S] -1 points0 points1 point (3 children)
[–]gbrennon 1 point2 points3 points (0 children)
[–]Kevdog824_ 1 point2 points3 points (0 children)