diff --git a/poetry.lock b/poetry.lock index 7e15543b..16da1a98 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1024,13 +1024,13 @@ typed-ast = ">=1.5.4,<2.0.0" [[package]] name = "dishka" -version = "0.6.0" +version = "0.8.0" description = "Minimal DI framework" optional = false python-versions = ">=3.10" files = [ - {file = "dishka-0.6.0-py3-none-any.whl", hash = "sha256:35ea6de1b4730c41859546cf24591733b8e172b10beccd50cd9d192e5981b972"}, - {file = "dishka-0.6.0.tar.gz", hash = "sha256:4d9b48f20c1f5f0dec4dc19b2b089eb5506422ff8e33da7b41fb2e5ebeb20507"}, + {file = "dishka-0.8.0-py3-none-any.whl", hash = "sha256:d439d801b79fa0d6d74eaffe9e651c4d66d8fe5dda4ba73deee38697d1858469"}, + {file = "dishka-0.8.0.tar.gz", hash = "sha256:928df14cd88687d7ca83e241b2d5e51eda9b9e1c53bfb67f397fa12e3e4a914e"}, ] [[package]] @@ -4159,4 +4159,4 @@ testing = ["coverage (>=5.0.3)", "zope.event", "zope.testing"] [metadata] lock-version = "2.0" python-versions = "~3.11" -content-hash = "fe462599693578a936387dc47921c278ac663cdbbfc9e86707210da5599231f5" +content-hash = "da8254550d262ea17b4729c4d15275fc4bf772454e3dbed1820159174ceb1528" diff --git a/pyproject.toml b/pyproject.toml index 91c1a24d..ea7251e7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,7 @@ openpyxl = "^3.0.10" lxml = "^4.9.2" matplotlib = "^3.7.1" greenlet = "<3.0.0" -dishka = "0.6.0" +dishka = "0.8.0" asgi-monitor = "^0.3.0" [tool.poetry.group.dev] diff --git a/shvatka/infrastructure/scheduler/context.py b/shvatka/infrastructure/scheduler/context.py index 4897daf2..af280a35 100644 --- a/shvatka/infrastructure/scheduler/context.py +++ b/shvatka/infrastructure/scheduler/context.py @@ -1,13 +1,6 @@ -from dataclasses import dataclass - -from aiogram import Bot from dishka import AsyncContainer from dishka.integrations.base import wrap_injection -from shvatka.core.interfaces.clients.file_storage import FileStorage -from shvatka.core.interfaces.scheduler import Scheduler -from shvatka.infrastructure.db.dao.holder import HolderDao - class ScheduledContextHolder: """ @@ -18,15 +11,6 @@ class ScheduledContextHolder: dishka: AsyncContainer -@dataclass -class ScheduledContext: - dao: HolderDao # need wrappers or protocols - bot: Bot # need wrappers or protocols - file_storage: FileStorage - scheduler: Scheduler - game_log_chat: int - - def inject(func): async def wrapper(*args, **kwargs): async with ScheduledContextHolder.dishka() as request_dishka: diff --git a/shvatka/infrastructure/scheduler/wrappers.py b/shvatka/infrastructure/scheduler/wrappers.py index 955355bd..4be27796 100644 --- a/shvatka/infrastructure/scheduler/wrappers.py +++ b/shvatka/infrastructure/scheduler/wrappers.py @@ -1,8 +1,7 @@ import typing -from typing import Annotated from aiogram import Bot -from dishka.integrations.base import Depends +from dishka.integrations.base import FromDishka from shvatka.core.interfaces.clients.file_storage import FileStorage from shvatka.infrastructure.db.dao.holder import HolderDao @@ -21,9 +20,9 @@ async def prepare_game_wrapper( game_id: int, author_id: int, - dao: Annotated[HolderDao, Depends()], - bot: Annotated[Bot, Depends()], - file_storage: Annotated[FileStorage, Depends()], + dao: FromDishka[HolderDao], + bot: FromDishka[Bot], + file_storage: FromDishka[FileStorage], ) -> None: author = await dao.player.get_by_id(author_id) game = await dao.game.get_by_id(game_id, author) @@ -38,11 +37,11 @@ async def prepare_game_wrapper( async def start_game_wrapper( game_id: int, author_id: int, - dao: Annotated[HolderDao, Depends()], - bot: Annotated[Bot, Depends()], - file_storage: Annotated[FileStorage, Depends()], - scheduler: Annotated[Scheduler, Depends()], - config: Annotated[BotConfig, Depends()], + dao: FromDishka[HolderDao], + bot: FromDishka[Bot], + file_storage: FromDishka[FileStorage], + scheduler: FromDishka[Scheduler], + config: FromDishka[BotConfig], ): game = await dao.game.get_full(game_id) assert author_id == game.author.id @@ -60,10 +59,10 @@ async def send_hint_wrapper( level_id: int, team_id: int, hint_number: int, - dao: Annotated[HolderDao, Depends()], - bot: Annotated[Bot, Depends()], - file_storage: Annotated[FileStorage, Depends()], - scheduler: Annotated[Scheduler, Depends()], + dao: FromDishka[HolderDao], + bot: FromDishka[Bot], + file_storage: FromDishka[FileStorage], + scheduler: FromDishka[Scheduler], ): level = await dao.level.get_by_id(level_id) team = await dao.team.get_by_id(team_id) @@ -84,10 +83,10 @@ async def send_hint_for_testing_wrapper( game_id: int, player_id: int, hint_number: int, - dao: Annotated[HolderDao, Depends()], - bot: Annotated[Bot, Depends()], - file_storage: Annotated[FileStorage, Depends()], - scheduler: Annotated[Scheduler, Depends()], + dao: FromDishka[HolderDao], + bot: FromDishka[Bot], + file_storage: FromDishka[FileStorage], + scheduler: FromDishka[Scheduler], ): level = await dao.level.get_by_id(level_id) game = await dao.game.get_by_id(game_id)