mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 17:47:02 +03:00
Make some changes in introduction docs
This commit is contained in:
parent
0df57272fd
commit
c8115ed44e
|
@ -1,6 +1,9 @@
|
|||
Dependency injection and inversion of control in Python
|
||||
-------------------------------------------------------
|
||||
|
||||
History
|
||||
~~~~~~~
|
||||
|
||||
Originally, dependency injection pattern got popular in languages with static
|
||||
typing, like Java. Dependency injection framework can
|
||||
significantly improve flexibility of the language with static typing. Also,
|
||||
|
@ -14,6 +17,9 @@ for Java. Also there is a meaning that dependency injection framework is
|
|||
something that Python developer would not ever need, cause dependency injection
|
||||
could be implemented easily using language fundamentals.
|
||||
|
||||
Discussion
|
||||
~~~~~~~~~~
|
||||
|
||||
It is true.
|
||||
|
||||
Partly.
|
||||
|
@ -75,6 +81,9 @@ Main design purposes of using inversion of control are:
|
|||
instead rely on contracts.
|
||||
+ To prevent side effects when replacing a module.
|
||||
|
||||
Example
|
||||
~~~~~~~
|
||||
|
||||
Let's go through next example:
|
||||
|
||||
.. literalinclude:: ../../../examples/ioc_demo/car_engine_1.py
|
||||
|
|
|
@ -8,11 +8,15 @@ interaction between each other.
|
|||
:width: 100%
|
||||
:align: center
|
||||
|
||||
There are 3 main entities:
|
||||
There are 3 main entities: providers, injections and catalogs.
|
||||
|
||||
.. glossary::
|
||||
+ All of the entities could be used in composition with each other or
|
||||
separatelly.
|
||||
+ Each of the entities could be extended via specialization.
|
||||
|
||||
Providers
|
||||
~~~~~~~~~
|
||||
|
||||
Providers are strategies of accesing objects. For example,
|
||||
:py:class:`dependency_injector.providers.Factory` creates new instance
|
||||
of provided class every time it is called.
|
||||
|
@ -23,6 +27,8 @@ There are 3 main entities:
|
|||
:py:class:`dependency_injector.providers.Provider`.
|
||||
|
||||
Injections
|
||||
~~~~~~~~~~
|
||||
|
||||
Injections are instructions for making dependency injections
|
||||
(there are several ways how they could be done). Injections are used
|
||||
mostly by :py:class:`dependency_injector.providers.Factory` and
|
||||
|
@ -31,12 +37,8 @@ There are 3 main entities:
|
|||
:py:class:`dependency_injector.injections.Injection`.
|
||||
|
||||
Catalogs
|
||||
~~~~~~~~~
|
||||
|
||||
Catalogs are collections of providers. They are used for grouping
|
||||
of providers by some principles. Base class is -
|
||||
:py:class:`dependency_injector.catalogs.DeclarativeCatalog`.
|
||||
|
||||
Some general principles about *Dependency Injector* entities:
|
||||
|
||||
+ All of the entities could be used in composition with each other or
|
||||
separatelly.
|
||||
+ Each of the entities could be extended via specialization.
|
||||
|
|
|
@ -8,9 +8,7 @@ class Components(catalogs.DeclarativeCatalog):
|
|||
"""Components catalog."""
|
||||
|
||||
service = providers.Factory(Service)
|
||||
|
||||
client = providers.Factory(Client,
|
||||
service=service)
|
||||
client = providers.Factory(Client, service=service)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue
Block a user