Make some changes in introduction docs

This commit is contained in:
Roman Mogilatov 2016-03-31 21:13:28 +03:00
parent 0df57272fd
commit c8115ed44e
3 changed files with 40 additions and 31 deletions

View File

@ -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

View File

@ -8,35 +8,37 @@ interaction between each other.
:width: 100%
:align: center
There are 3 main entities:
.. glossary::
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.
:py:class:`dependency_injector.providers.Singleton` creates provided
instance once and returns it on every next call. Providers could be
injected into each other. Providers could be overridden by another
providers. Base class is -
: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
:py:class:`dependency_injector.providers.Singleton` providers, but
these are not only cases. Base class is -
: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:
There are 3 main entities: providers, injections and catalogs.
+ 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.
:py:class:`dependency_injector.providers.Singleton` creates provided
instance once and returns it on every next call. Providers could be
injected into each other. Providers could be overridden by another
providers. Base class is -
: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
:py:class:`dependency_injector.providers.Singleton` providers, but
these are not only cases. Base class is -
: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`.

View File

@ -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__':