feat: add dependency providers
This commit is contained in:
parent
87c4036a6e
commit
94dd4a752e
21
src/proxy_pool/common/dependencies.py
Normal file
21
src/proxy_pool/common/dependencies.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
from collections.abc import AsyncGenerator
|
||||||
|
|
||||||
|
from fastapi import Request
|
||||||
|
from redis.asyncio import Redis
|
||||||
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
|
from proxy_pool.plugins.registry import PluginRegistry
|
||||||
|
|
||||||
|
|
||||||
|
async def get_db(request: Request) -> AsyncGenerator[AsyncSession, None]:
|
||||||
|
session_factory = request.app.state.session_factory
|
||||||
|
async with session_factory() as session:
|
||||||
|
yield session
|
||||||
|
|
||||||
|
|
||||||
|
def get_redis(request: Request) -> Redis:
|
||||||
|
return request.app.state.redis
|
||||||
|
|
||||||
|
|
||||||
|
def get_registry(request: Request) -> PluginRegistry:
|
||||||
|
return request.app.state.registry
|
||||||
Loading…
x
Reference in New Issue
Block a user