From 544756801045944abb7420fa5514a92693a76710 Mon Sep 17 00:00:00 2001 From: Nnenty Date: Thu, 21 Nov 2024 21:52:25 +0300 Subject: [PATCH 1/3] Fix `docs/advanced/components.rst` typos --- docs/advanced/components.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/advanced/components.rst b/docs/advanced/components.rst index 54fb46b4..af8b4b45 100644 --- a/docs/advanced/components.rst +++ b/docs/advanced/components.rst @@ -9,7 +9,7 @@ Problem definition As you know, container can be created from multiple providers, which are dynamically bound together. It allows you to reuse them or partially override in tests. It works well while you have different types across all provided objects. But what if there are some intersections. Let's talk about three situations: 1. Only several types are used with different meaning within a monolithic app. -2. Several parts of an application are developed them or less independently, while they used within same processing context +2. Several parts of an application are developed them more or less independently, while they used within same processing context 3. You have a modular application with multiple bounded contexts **First situation** can appear when you have for-example multiple thread pools for different tasks or multiple database connections for different databases. While they have special meaning you distinguish them by creating new types From fdda0f4676ecf6edbcf97ea7950946e418b26ec6 Mon Sep 17 00:00:00 2001 From: Andrey Tikhonov <17@itishka.org> Date: Sat, 23 Nov 2024 09:17:53 +0100 Subject: [PATCH 2/3] Fix auiinject failed on latest aiohttp --- src/dishka/integrations/aiohttp.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/dishka/integrations/aiohttp.py b/src/dishka/integrations/aiohttp.py index 80e672d2..c507e5e6 100644 --- a/src/dishka/integrations/aiohttp.py +++ b/src/dishka/integrations/aiohttp.py @@ -70,7 +70,11 @@ def _inject_routes(router: web.UrlDispatcher) -> None: _inject_route(route) for resource in router.resources(): - for route in resource._routes: # type: ignore[attr-defined] # noqa: SLF001 + try: + routes = iter(resource) + except TypeError: + continue + for route in routes: _inject_route(route) From 0682bfee87fa5db39015fb28e94bcb7a375ed532 Mon Sep 17 00:00:00 2001 From: Andrey Tikhonov <17@itishka.org> Date: Thu, 28 Nov 2024 17:57:30 +0100 Subject: [PATCH 3/3] fix docs for override --- docs/provider/alias.rst | 16 +++++++++------- docs/provider/from_context.rst | 15 +++++++++------ docs/provider/provide.rst | 19 +++++++++++++------ 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/docs/provider/alias.rst b/docs/provider/alias.rst index 945de81d..b2a0ccbd 100644 --- a/docs/provider/alias.rst +++ b/docs/provider/alias.rst @@ -24,13 +24,15 @@ Additionally, alias has own setting for caching: it caches by default regardless .. code-block:: python - from dishka import WithParents, provide, Provider, Scope, alias + from dishka import provide, Provider, Scope, alias, make_container + class MyProvider(Provider): scope=Scope.APP - a = provide(lambda: 1, provides=int) - a_alias = alias(float, provides=int) - a_alias_override = alias(float, provides=int, override=True) + get_int = provide(int) + get_float = provide(float) + + a_alias = alias(int, provides=complex) + a_alias_override = alias(float, provides=complex, override=True) - container = make_async_container(MyProvider()) - a = await container.get(int) - # 2 + container = make_container(MyProvider()) + a = container.get(complex) # 0.0 diff --git a/docs/provider/from_context.rst b/docs/provider/from_context.rst index 67f640a3..ce9fc5da 100644 --- a/docs/provider/from_context.rst +++ b/docs/provider/from_context.rst @@ -25,16 +25,19 @@ You can put some data manually when entering scope and rely on it in your provid pass -* Do you want to override the ``from_context``? To do this, specify the parameter ``override=True``. This can be checked when passing proper ``validation_settings`` when creating container. +* Do you want to override factory with ``from_context``? To do this, specify the parameter ``override=True``. This can be checked when passing proper ``validation_settings`` when creating container. .. code-block:: python - from dishka import WithParents, from_context, Provider, Scope + from dishka import provide, from_context, Provider, Scope, make_container class MyProvider(Provider): scope=Scope.APP - a = from_context(provides=int) + + @provide + def get_int(self) -> int: + return 1 + a_override = from_context(provides=int, override=True) - container = make_async_container(MyProvider()) - a = await container.get(int) - # 2 + container = make_container(MyProvider(), context={int: 2}) + a = container.get(int) # 2 diff --git a/docs/provider/provide.rst b/docs/provider/provide.rst index f95f2a93..2b510052 100644 --- a/docs/provider/provide.rst +++ b/docs/provider/provide.rst @@ -159,14 +159,21 @@ WithParents generates only one factory and many aliases and is equivalent to ``A .. code-block:: python - from dishka import WithParents, provide, Provider, Scope + from dishka import provide, Provider, Scope, make_container + class MyProvider(Provider): scope=Scope.APP - a = provide(lambda: 1, provides=int) - a_override = provide(lambda: 2, provides=int, override=True) - container = make_async_container(MyProvider()) - a = await container.get(int) - # 2 + + @provide + def get_int(self) -> int: + return 1 + + @provide(override=True) + def get_int2(self) -> int: + return 2 + + container = make_container(MyProvider()) + a = container.get(int) # 2 * You can use factory with Generic classes