26 lines
758 B
Python
26 lines
758 B
Python
"""Доступ к разделяемым компонентам приложения через app.state.
|
|
|
|
Компоненты (Storage, DownloadQueue, EventBus, WorkerPool) создаются в lifespan
|
|
в main.py и кладутся в app.state. Роуты достают их отсюда через Depends.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from fastapi import Request
|
|
|
|
from app.core.events import EventBus
|
|
from app.core.queue import DownloadQueue
|
|
from app.core.storage import Storage
|
|
|
|
|
|
def get_storage(request: Request) -> Storage:
|
|
return request.app.state.storage
|
|
|
|
|
|
def get_queue(request: Request) -> DownloadQueue:
|
|
return request.app.state.queue
|
|
|
|
|
|
def get_events(request: Request) -> EventBus:
|
|
return request.app.state.events
|