mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-30 05:23:59 +03:00
bf978601ba
* Refactor services mini app with single container * Make few little fixes to single container app * Update requirements.txt for single container example * Refactor multiple containers example * Add single container docs page * Create multiple containers page
94 lines
2.9 KiB
ReStructuredText
94 lines
2.9 KiB
ReStructuredText
.. _application-single-container:
|
|
|
|
Application example (single container)
|
|
======================================
|
|
|
|
.. meta::
|
|
:keywords: Python,Dependency Injection,Inversion of Control,Container,Example,Application,
|
|
Framework,AWS,boto3,client
|
|
:description: This example shows how you can create an application using a single declarative
|
|
container. We build an example Python micro application following the dependency
|
|
injection principle. It consists from several services with a domain logic that
|
|
have dependencies on database & AWS S3.
|
|
|
|
This example shows how you can create an application using a single declarative container. Using
|
|
a single declarative container is a good choice for small or moderate size application. For
|
|
building a large application refer to :ref:`application-multiple-containers`.
|
|
|
|
We build an example micro application following the dependency injection principle. It consists
|
|
of several services with a domain logic. The services have dependencies on database & AWS S3.
|
|
|
|
.. image:: images/application.png
|
|
:width: 100%
|
|
:align: center
|
|
|
|
Start from the scratch or jump to the section:
|
|
|
|
.. contents::
|
|
:local:
|
|
:backlinks: none
|
|
|
|
You can find the source code and instructions for running on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/application-single-container>`_.
|
|
|
|
Application structure
|
|
---------------------
|
|
|
|
Application consists of an ``example`` package, several configuration files and a
|
|
``requirements.txt`` file.
|
|
|
|
.. code-block:: bash
|
|
|
|
./
|
|
├── example/
|
|
│ ├── __init__.py
|
|
│ ├── __main__.py
|
|
│ ├── containers.py
|
|
│ └── services.py
|
|
├── config.ini
|
|
├── logging.ini
|
|
└── requirements.txt
|
|
|
|
Container
|
|
---------
|
|
|
|
Listing of the ``example/containers.py``:
|
|
|
|
.. literalinclude:: ../../examples/miniapps/application-single-container/example/containers.py
|
|
:language: python
|
|
|
|
Main module
|
|
-----------
|
|
|
|
Listing of the ``example/__main__.py``:
|
|
|
|
.. literalinclude:: ../../examples/miniapps/application-single-container/example/__main__.py
|
|
:language: python
|
|
|
|
Services
|
|
--------
|
|
|
|
Listing of the ``example/services.py``:
|
|
|
|
.. literalinclude:: ../../examples/miniapps/application-single-container/example/services.py
|
|
:language: python
|
|
|
|
Configuration
|
|
-------------
|
|
|
|
Listing of the ``config.ini``:
|
|
|
|
.. literalinclude:: ../../examples/miniapps/application-single-container/config.ini
|
|
:language: ini
|
|
|
|
Listing of the ``logging.ini``:
|
|
|
|
.. literalinclude:: ../../examples/miniapps/application-single-container/logging.ini
|
|
:language: ini
|
|
|
|
Run the application
|
|
-------------------
|
|
|
|
You can find the source code and instructions for running on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/application-single-container>`_.
|
|
|
|
.. disqus::
|