-
Notifications
You must be signed in to change notification settings - Fork 548
Closed
Labels
t-toolingIssues with this label are in the ownership of the tooling team.Issues with this label are in the ownership of the tooling team.
Description
Hello, I am looking for a way to inject or pass arbitrary data to the context object. Similar to what is possible in fastapi via app.state or via dependencies:
from fastapi import FastAPI
app = FastAPI()
app.state.custom_context = {"a": "b"}
# In separate file
router = Router()
@router.get("/items/{item_id}")
async def read_items(item_id: str, request: Request):
example_context = request.app.state.custom_context
return items[item_id]My use case is that I have the handlers in separate files and I would like to pass general run information to the handlers, without the need for database requests. I am aware of user_data, but I am not sure this is appropriate here, since it is more tied to the Request and not the overall run. Furthermore, I don't see a straight-forward way to pass the data from the start_urls? Is it possible to abuse the pre_navigation_hook or something similar?
Any guidance would be helpful. Thanks!
Metadata
Metadata
Assignees
Labels
t-toolingIssues with this label are in the ownership of the tooling team.Issues with this label are in the ownership of the tooling team.