mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-05-23 05:56:19 +03:00
Update aiohttp example and tutorial
This commit is contained in:
parent
315f0c0a62
commit
38514c29c5
|
@ -526,17 +526,18 @@ the ``index`` handler. We will use :ref:`wiring` feature.
|
||||||
Edit ``handlers.py``:
|
Edit ``handlers.py``:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
:emphasize-lines: 4-7,10-13,17
|
:emphasize-lines: 4-7,10-14,18
|
||||||
|
|
||||||
"""Handlers module."""
|
"""Handlers module."""
|
||||||
|
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
from dependency_injector.wiring import Provide
|
from dependency_injector.wiring import inject, Provide
|
||||||
|
|
||||||
from .services import SearchService
|
from .services import SearchService
|
||||||
from .containers import Container
|
from .containers import Container
|
||||||
|
|
||||||
|
|
||||||
|
@inject
|
||||||
async def index(
|
async def index(
|
||||||
request: web.Request,
|
request: web.Request,
|
||||||
search_service: SearchService = Provide[Container.search_service],
|
search_service: SearchService = Provide[Container.search_service],
|
||||||
|
@ -645,17 +646,18 @@ Let's make some refactoring. We will move these values to the config.
|
||||||
Edit ``handlers.py``:
|
Edit ``handlers.py``:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
:emphasize-lines: 13-14,16-17
|
:emphasize-lines: 14-15,17-18
|
||||||
|
|
||||||
"""Handlers module."""
|
"""Handlers module."""
|
||||||
|
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
from dependency_injector.wiring import Provide
|
from dependency_injector.wiring import inject, Provide
|
||||||
|
|
||||||
from .services import SearchService
|
from .services import SearchService
|
||||||
from .containers import Container
|
from .containers import Container
|
||||||
|
|
||||||
|
|
||||||
|
@inject
|
||||||
async def index(
|
async def index(
|
||||||
request: web.Request,
|
request: web.Request,
|
||||||
search_service: SearchService = Provide[Container.search_service],
|
search_service: SearchService = Provide[Container.search_service],
|
||||||
|
@ -821,11 +823,11 @@ You should see:
|
||||||
giphynavigator/application.py 12 0 100%
|
giphynavigator/application.py 12 0 100%
|
||||||
giphynavigator/containers.py 6 0 100%
|
giphynavigator/containers.py 6 0 100%
|
||||||
giphynavigator/giphy.py 14 9 36%
|
giphynavigator/giphy.py 14 9 36%
|
||||||
giphynavigator/handlers.py 9 0 100%
|
giphynavigator/handlers.py 10 0 100%
|
||||||
giphynavigator/services.py 9 1 89%
|
giphynavigator/services.py 9 1 89%
|
||||||
giphynavigator/tests.py 37 0 100%
|
giphynavigator/tests.py 37 0 100%
|
||||||
---------------------------------------------------
|
---------------------------------------------------
|
||||||
TOTAL 87 10 89%
|
TOTAL 88 10 89%
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
|
|
|
@ -111,8 +111,8 @@ The output should be something like:
|
||||||
giphynavigator/application.py 12 0 100%
|
giphynavigator/application.py 12 0 100%
|
||||||
giphynavigator/containers.py 6 0 100%
|
giphynavigator/containers.py 6 0 100%
|
||||||
giphynavigator/giphy.py 14 9 36%
|
giphynavigator/giphy.py 14 9 36%
|
||||||
giphynavigator/handlers.py 9 0 100%
|
giphynavigator/handlers.py 10 0 100%
|
||||||
giphynavigator/services.py 9 1 89%
|
giphynavigator/services.py 9 1 89%
|
||||||
giphynavigator/tests.py 37 0 100%
|
giphynavigator/tests.py 37 0 100%
|
||||||
---------------------------------------------------
|
---------------------------------------------------
|
||||||
TOTAL 87 10 89%
|
TOTAL 88 10 89%
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
"""Handlers module."""
|
"""Handlers module."""
|
||||||
|
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
from dependency_injector.wiring import Provide
|
from dependency_injector.wiring import inject, Provide
|
||||||
|
|
||||||
from .services import SearchService
|
from .services import SearchService
|
||||||
from .containers import Container
|
from .containers import Container
|
||||||
|
|
||||||
|
|
||||||
|
@inject
|
||||||
async def index(
|
async def index(
|
||||||
request: web.Request,
|
request: web.Request,
|
||||||
search_service: SearchService = Provide[Container.search_service],
|
search_service: SearchService = Provide[Container.search_service],
|
||||||
|
|
Loading…
Reference in New Issue
Block a user