mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-07-06 13:23:15 +03:00
Update docs and README
This commit is contained in:
parent
5474bd2ad1
commit
1b6e3fd269
|
@ -65,7 +65,7 @@ Key features of the ``Dependency Injector``:
|
|||
- **Containers**. Provides declarative and dynamic containers.
|
||||
See `Containers <https://python-dependency-injector.ets-labs.org/containers/index.html>`_.
|
||||
- **Resources**. Helps with initialization and configuring of logging, event loop, thread
|
||||
or process pool, etc.
|
||||
or process pool, etc. Can be used for per-function execution scope in tandem with wiring.
|
||||
See `Resource provider <https://python-dependency-injector.ets-labs.org/providers/resource.html>`_.
|
||||
- **Wiring**. Injects dependencies into functions and methods. Helps integrating with
|
||||
other frameworks: Django, Flask, Aiohttp, etc.
|
||||
|
|
|
@ -73,7 +73,8 @@ Key features of the ``Dependency Injector``:
|
|||
- **Configuration**. Reads configuration from ``yaml`` & ``ini`` files, environment variables
|
||||
and dictionaries. See :ref:`configuration-provider`.
|
||||
- **Resources**. Helps with initialization and configuring of logging, event loop, thread
|
||||
or process pool, etc. See :ref:`resource-provider`.
|
||||
or process pool, etc. Can be used for per-function execution scope in tandem with wiring.
|
||||
See :ref:`resource-provider`.
|
||||
- **Containers**. Provides declarative and dynamic containers. See :ref:`containers`.
|
||||
- **Wiring**. Injects dependencies into functions and methods. Helps integrating with
|
||||
other frameworks: Django, Flask, Aiohttp, etc. See :ref:`wiring`.
|
||||
|
|
|
@ -19,7 +19,8 @@ Key features of the ``Dependency Injector``:
|
|||
- **Configuration**. Reads configuration from ``yaml`` & ``ini`` files, environment variables
|
||||
and dictionaries. See :ref:`configuration-provider`.
|
||||
- **Resources**. Helps with initialization and configuring of logging, event loop, thread
|
||||
or process pool, etc. See :ref:`resource-provider`.
|
||||
or process pool, etc. Can be used for per-function execution scope in tandem with wiring.
|
||||
See :ref:`resource-provider`.
|
||||
- **Containers**. Provides declarative and dynamic containers. See :ref:`containers`.
|
||||
- **Wiring**. Injects dependencies into functions and methods. Helps integrating with
|
||||
other frameworks: Django, Flask, Aiohttp, etc. See :ref:`wiring`.
|
||||
|
|
|
@ -203,4 +203,36 @@ first argument.
|
|||
# shutdown
|
||||
...
|
||||
|
||||
|
||||
.. _resource-provider-wiring-closing:
|
||||
|
||||
Resources, wiring and per-function execution scope
|
||||
--------------------------------------------------
|
||||
|
||||
You can compound ``Resource`` provider with :ref:`wiring` to implement per-function
|
||||
execution scope. For doing this you need to use additional ``Closing`` marker from
|
||||
``wiring`` module.
|
||||
|
||||
.. literalinclude:: ../../examples/wiring/flask_resource_closing.py
|
||||
:language: python
|
||||
:lines: 3-
|
||||
:emphasize-lines: 23
|
||||
|
||||
Framework initializes and injects the resource into the function. With the ``Closing`` marker
|
||||
framework calls resource ``shutdown()`` method when function execution is over.
|
||||
|
||||
The example above produces next output:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
Init service
|
||||
Shutdown service
|
||||
127.0.0.1 - - [29/Oct/2020 22:39:40] "GET / HTTP/1.1" 200 -
|
||||
Init service
|
||||
Shutdown service
|
||||
127.0.0.1 - - [29/Oct/2020 22:39:41] "GET / HTTP/1.1" 200 -
|
||||
Init service
|
||||
Shutdown service
|
||||
127.0.0.1 - - [29/Oct/2020 22:39:41] "GET / HTTP/1.1" 200 -
|
||||
|
||||
.. disqus::
|
||||
|
|
|
@ -66,6 +66,10 @@ You can use configuration, provided instance and sub-container providers as you
|
|||
def foo(bar: Bar = Provide[Container.subcontainer.bar]):
|
||||
...
|
||||
|
||||
|
||||
You can compound wiring and ``Resource`` provider to implement per-function execution scope.
|
||||
See :ref:`Resources, wiring and per-function execution scope <resource-provider-wiring-closing>` for details.
|
||||
|
||||
Wiring with modules and packages
|
||||
--------------------------------
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user