Can app dependencies being injected into startup events via Depends()?
#8736
-
First Check
Commit to Help
Example Codefrom fastapi import FastAPI
app = FastAPI()
@app.on_event("startup")
def access_settings(settings: Settings = Depends(get_settings)):
print(settings.setting_name)DescriptionIs is possible to access app dependencies in a startup event? When I try this in my application, I get Operating SystemLinux Operating System DetailsNo response FastAPI Version0.70.1 Python Version3.10.1 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Answered by
chbndrhnns
Jan 8, 2022
Replies: 1 comment
-
|
No, the dependency injection feature depends on the request context which is only available with an incoming request. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Kludex
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No, the dependency injection feature depends on the request context which is only available with an incoming request.