2016-03-30 17:10:43 +03:00
|
|
|
Structure of Dependency Injector
|
|
|
|
--------------------------------
|
2016-03-31 21:00:48 +03:00
|
|
|
|
2016-04-11 23:16:46 +03:00
|
|
|
.. meta::
|
2016-04-23 15:00:06 +03:00
|
|
|
:keywords: Python,DI,Dependency injection,IoC,Inversion of Control
|
2016-04-11 23:16:46 +03:00
|
|
|
:description: This article describes "Dependency Injector" framework
|
|
|
|
components and their interaction between each other.
|
2016-06-03 00:48:06 +03:00
|
|
|
Providers and containers are the former components of
|
|
|
|
the framework.
|
2016-04-11 23:16:46 +03:00
|
|
|
|
2016-03-31 21:00:48 +03:00
|
|
|
Current section describes *Dependency Injector* main entities and their
|
|
|
|
interaction between each other.
|
|
|
|
|
|
|
|
.. image:: /images/internals.png
|
|
|
|
:width: 100%
|
|
|
|
:align: center
|
|
|
|
|
2016-06-03 17:33:30 +03:00
|
|
|
There are 2 main entities: providers & containers.
|
2016-03-31 21:13:28 +03:00
|
|
|
|
|
|
|
Providers
|
|
|
|
~~~~~~~~~
|
|
|
|
|
2016-06-02 20:27:01 +03:00
|
|
|
Providers are strategies of accessing objects. For example,
|
2016-03-31 21:13:28 +03:00
|
|
|
: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
|
2016-06-03 17:33:30 +03:00
|
|
|
instance once and returns it on every next call. Base class is -
|
2016-03-31 21:13:28 +03:00
|
|
|
:py:class:`dependency_injector.providers.Provider`.
|
|
|
|
|
2016-06-03 00:48:06 +03:00
|
|
|
Providers could be:
|
2016-03-31 21:13:28 +03:00
|
|
|
|
2016-06-03 00:48:06 +03:00
|
|
|
+ Injected into each other.
|
|
|
|
+ Overridden by each other.
|
|
|
|
+ Extended.
|
2016-03-31 21:13:28 +03:00
|
|
|
|
2016-06-03 00:48:06 +03:00
|
|
|
Containers
|
|
|
|
~~~~~~~~~~
|
2016-03-31 21:13:28 +03:00
|
|
|
|
2016-06-03 00:48:06 +03:00
|
|
|
Containers are collections of providers. They are used for grouping
|
2016-03-31 21:13:28 +03:00
|
|
|
of providers by some principles. Base class is -
|
2016-06-03 00:48:06 +03:00
|
|
|
:py:class:`dependency_injector.containers.DeclarativeContainer`.
|
|
|
|
|
|
|
|
Containers could be:
|
|
|
|
|
|
|
|
+ Overridden by each other.
|
|
|
|
+ Copied from each other.
|
|
|
|
+ Extended.
|
2017-02-28 23:00:08 +03:00
|
|
|
|
|
|
|
|
|
|
|
.. disqus::
|