Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tishka17 committed Nov 28, 2024
2 parents e1b8772 + 76feb1d commit 4b7ef13
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/advanced/components.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions docs/provider/alias.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 9 additions & 6 deletions docs/provider/from_context.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 13 additions & 6 deletions docs/provider/provide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/dishka/integrations/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 4b7ef13

Please sign in to comment.