@@ -23,6 +23,10 @@ fastapi's handler function.
2323I have a script called ` test_script.py ` so my app can be found at ` test_script:app ` .
2424We use strings to resolve application to bypass circular imports.
2525
26+ Also, as you can see, we use ` TaskiqDepends ` for Request. That's because
27+ taskiq dependency resolver must know that this type must be injected. FastAPI disallow
28+ Depends for Request type. That's why we use ` TaskiqDepends ` .
29+
2630``` python
2731from fastapi import FastAPI, Request
2832from pydantic import BaseModel
@@ -73,6 +77,8 @@ async def app_shutdown():
7377taskiq_fastapi.init(broker, " test_script:app" )
7478
7579
80+ # We use TaskiqDepends here, becuase if we use FastAPIDepends fastapi
81+ # initilization will fail.
7682def get_redis_pool (request : Request = TaskiqDepends()) -> ConnectionPool:
7783 return request.app.state.redis_pool
7884
@@ -81,6 +87,9 @@ def get_redis_pool(request: Request = TaskiqDepends()) -> ConnectionPool:
8187async def my_redis_task (
8288 key : str ,
8389 val : str ,
90+ # Here we depend using TaskiqDepends.
91+ # Please use TaskiqDepends for all tasks to be resolved correctly.
92+ # Or dependencies won't be injected.
8493 pool : ConnectionPool = TaskiqDepends(get_redis_pool),
8594):
8695 async with Redis(connection_pool = pool) as redis:
0 commit comments