From f6daa092ba9a25aa39bfe671becb84e128e691df Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Mon, 5 Oct 2020 19:18:08 -0400 Subject: [PATCH] Add aiohttp example to the docs --- docs/examples/aiohttp.rst | 79 +++++++++++++++++++++++++++++++++++++++ docs/examples/django.rst | 2 +- docs/examples/flask.rst | 2 +- docs/examples/index.rst | 1 + docs/examples/sanic.rst | 2 +- 5 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 docs/examples/aiohttp.rst diff --git a/docs/examples/aiohttp.rst b/docs/examples/aiohttp.rst new file mode 100644 index 00000000..1a884102 --- /dev/null +++ b/docs/examples/aiohttp.rst @@ -0,0 +1,79 @@ +Aiohttp example +=============== + +.. meta:: + :keywords: Python,Dependency Injection,Aiohttp,Example + :description: This example demonstrates a usage of the Aiohttp and Dependency Injector. + + +This example shows how to use ``Dependency Injector`` with `Aiohttp `_. + +The example application is a REST API that searches for funny GIFs on the `Giphy `_. + +The source code is available on the `Github `_. + +:ref:`aiohttp-tutorial` demonstrates how to build this application step-by-step. + +Application structure +--------------------- + +Application has next structure: + +.. code-block:: bash + + ./ + ├── giphynavigator/ + │ ├── __init__.py + │ ├── application.py + │ ├── containers.py + │ ├── giphy.py + │ ├── handlers.py + │ ├── services.py + │ └── tests.py + ├── config.yml + └── requirements.txt + +Container +--------- + +Declarative container is defined in ``giphynavigator/containers.py``: + +.. literalinclude:: ../../examples/miniapps/aiohttp/giphynavigator/containers.py + :language: python + +Handlers +-------- + +Handler has dependencies on search service and some config options. The dependencies are injected +using :ref:`wiring` feature. + +Listing of ``giphynavigator/handlers.py``: + +.. literalinclude:: ../../examples/miniapps/aiohttp/giphynavigator/handlers.py + :language: python + +Application factory +------------------- +Application factory creates container, wires it with the ``handlers`` module, creates +``Aiohttp`` app and setup routes. + +Listing of ``giphynavigator/application.py``: + +.. literalinclude:: ../../examples/miniapps/aiohttp/giphynavigator/application.py + :language: python + +Tests +----- + +Tests use :ref:`provider-overriding` feature to replace giphy client with a mock ``giphynavigator/tests.py``: + +.. literalinclude:: ../../examples/miniapps/aiohttp/giphynavigator/tests.py + :language: python + :emphasize-lines: 32,59,73 + +Sources +------- + +Explore the sources on the `Github `_. + +.. disqus:: diff --git a/docs/examples/django.rst b/docs/examples/django.rst index 5451705f..8c36c6be 100644 --- a/docs/examples/django.rst +++ b/docs/examples/django.rst @@ -81,7 +81,7 @@ Container is wired to the ``views`` module in the app config ``web/apps.py``: Tests ----- -Tests use :ref:`provider-overriding` feature to replace search service with a mock ``web/tests.py``: +Tests use :ref:`provider-overriding` feature to replace github client with a mock ``web/tests.py``: .. literalinclude:: ../../examples/miniapps/django/web/tests.py :language: python diff --git a/docs/examples/flask.rst b/docs/examples/flask.rst index f4750ced..b0da80c9 100644 --- a/docs/examples/flask.rst +++ b/docs/examples/flask.rst @@ -71,7 +71,7 @@ Listing of ``githubnavigator/application.py``: Tests ----- -Tests use :ref:`provider-overriding` feature to replace search service with a mock ``githubnavigator/tests.py``: +Tests use :ref:`provider-overriding` feature to replace github client with a mock ``githubnavigator/tests.py``: .. literalinclude:: ../../examples/miniapps/flask/githubnavigator/tests.py :language: python diff --git a/docs/examples/index.rst b/docs/examples/index.rst index 452ff8f5..16b7fc0a 100644 --- a/docs/examples/index.rst +++ b/docs/examples/index.rst @@ -15,6 +15,7 @@ Explore the examples to see the ``Dependency Injector`` in action. decoupled-packages django flask + aiohttp sanic .. disqus:: diff --git a/docs/examples/sanic.rst b/docs/examples/sanic.rst index 4a15f957..5b9a34c4 100644 --- a/docs/examples/sanic.rst +++ b/docs/examples/sanic.rst @@ -64,7 +64,7 @@ Listing of ``giphynavigator/application.py``: Tests ----- -Tests use :ref:`provider-overriding` feature to replace search service with a mock ``giphynavigator/tests.py``: +Tests use :ref:`provider-overriding` feature to replace giphy client with a mock ``giphynavigator/tests.py``: .. literalinclude:: ../../examples/miniapps/sanic/giphynavigator/tests.py :language: python