mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 09:36:48 +03:00
Adding external dependency provider description and examples renaming
This commit is contained in:
parent
ca4db90ce3
commit
fab6a5c610
|
@ -20,6 +20,8 @@ There are few *Instance* providers:
|
||||||
- ``Singleton`` provider creates new instance of specified class on first
|
- ``Singleton`` provider creates new instance of specified class on first
|
||||||
call and returns same instance on every next call.
|
call and returns same instance on every next call.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
"""`NewInstance` and `Singleton` providers example."""
|
"""`NewInstance` and `Singleton` providers example."""
|
||||||
|
@ -131,6 +133,8 @@ There are four of static providers: ``Class``, ``Object``, ``Function`` and
|
||||||
``Value``. All of them has the same behaviour, but usage of anyone is
|
``Value``. All of them has the same behaviour, but usage of anyone is
|
||||||
predicted by readability and providable object's type.
|
predicted by readability and providable object's type.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
"""Static providers example."""
|
"""Static providers example."""
|
||||||
|
@ -153,8 +157,8 @@ predicted by readability and providable object's type.
|
||||||
value_provider = Value(123)
|
value_provider = Value(123)
|
||||||
assert value_provider() == 123
|
assert value_provider() == 123
|
||||||
|
|
||||||
Callable provider
|
Callable providers
|
||||||
-----------------
|
------------------
|
||||||
|
|
||||||
``Callable`` provider is a provider that decorates particular callable with
|
``Callable`` provider is a provider that decorates particular callable with
|
||||||
some injections. Every call of this provider returns result of call of initial
|
some injections. Every call of this provider returns result of call of initial
|
||||||
|
@ -164,7 +168,7 @@ callable.
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
"""`Callable` provider examples."""
|
"""`Callable` providers examples."""
|
||||||
|
|
||||||
from objects.providers import Callable
|
from objects.providers import Callable
|
||||||
from objects.providers import Singleton
|
from objects.providers import Singleton
|
||||||
|
@ -191,13 +195,31 @@ callable.
|
||||||
assert some_function(2) == 2
|
assert some_function(2) == 2
|
||||||
assert some_function(2231) == 2231
|
assert some_function(2231) == 2231
|
||||||
|
|
||||||
External dependency provider
|
|
||||||
----------------------------
|
|
||||||
|
|
||||||
``ExternalDependency`` provider can be useful for
|
External dependency providers
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
Config provider
|
``ExternalDependency`` provider can be useful for development of self-sufficient
|
||||||
---------------
|
libraries / modules / applications, that has required external dependencies.
|
||||||
|
|
||||||
|
For example, you have created self-sufficient library / module / application,
|
||||||
|
that has dependency on *SQLAlchemy*. Second step you want to do is to make this
|
||||||
|
software component to be easy reusable by wide amount of developers and to be
|
||||||
|
easily integrated into many applications. It may be good idea, to move all
|
||||||
|
external dependencies (like *SQLAlchemy*) to the top level and make them to be
|
||||||
|
injected on your software component's initialization. It will make third party
|
||||||
|
developers feel themselves more free about integration of yours component in
|
||||||
|
their applications because of they would be able to find right place / right
|
||||||
|
way for doing this in their application's architectures.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
import this
|
||||||
|
|
||||||
|
Config providers
|
||||||
|
----------------
|
||||||
|
|
||||||
Providers delegation
|
Providers delegation
|
||||||
--------------------
|
--------------------
|
||||||
|
@ -211,7 +233,7 @@ Example:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
"""Provider overriding example."""
|
"""Providers overriding example."""
|
||||||
|
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
"""`Callable` provider examples."""
|
"""`Callable` providers examples."""
|
||||||
|
|
||||||
from objects.providers import Callable
|
from objects.providers import Callable
|
||||||
from objects.providers import Singleton
|
from objects.providers import Singleton
|
|
@ -1,4 +1,4 @@
|
||||||
"""External dependency example."""
|
"""External dependency providers example."""
|
||||||
|
|
||||||
from objects.catalog import AbstractCatalog
|
from objects.catalog import AbstractCatalog
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
"""Provider overriding example."""
|
"""Providers overriding example."""
|
||||||
|
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user