.. _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::
