You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
and dictionaries. See :ref:`configuration-provider`.
79
+
- **Containers**. Provides declarative and dynamic containers. See :ref:`containers`.
80
+
- **Performance**. Fast. Written in ``Cython``.
81
+
- **Maturity**. Mature and production-ready. Well-tested, documented and supported.
73
82
74
-
- **No autowiring.** The framework does NOT do any autowiring / autoresolving of the dependencies. You need to specify everything explicitly. Because *"Explicit is better than implicit" (PEP20)*.
75
-
- **Does not pollute your code.** Your application does NOT know and does NOT depend on the framework. No ``@inject`` decorators, annotations, patching or any other magic tricks.
83
+
.. code-block:: python
76
84
77
-
``Dependency Injector`` makes a simple contract with you:
85
+
from dependency_injector import containers, providers
78
86
79
-
- You tell the framework how to assemble your objects
80
-
- The framework does it for you
81
87
82
-
The power of the ``Dependency Injector`` is in its simplicity and straightforwardness. It is a simple tool for the powerful concept.
88
+
classContainer(containers.DeclarativeContainer):
89
+
90
+
config = providers.Configuration()
91
+
92
+
api_client = providers.Singleton(
93
+
ApiClient,
94
+
api_key=config.api_key,
95
+
timeout=config.timeout.as_int(),
96
+
)
97
+
98
+
service = providers.Factory(
99
+
Service,
100
+
api_client=api_client,
101
+
)
102
+
103
+
104
+
if__name__=='__main__':
105
+
container = Container()
106
+
container.config.api_key.from_env('API_KEY')
107
+
container.config.timeout.from_env('TIMEOUT')
108
+
109
+
service = container.service()
83
110
84
111
With the ``Dependency Injector`` you keep **application structure in one place**.
85
112
This place is called **the container**. You use the container to manage all the components of the
and dictionaries. See :ref:`configuration-provider`.
19
+
- **Containers**. Provides declarative and dynamic containers. See :ref:`containers`.
20
+
- **Performance**. Fast. Written in ``Cython``.
21
+
- **Maturity**. Mature and production-ready. Well-tested, documented and supported.
15
22
16
-
It stands on two principles:
23
+
The framework stands on two principles:
17
24
18
-
- Explicit is better than implicit (PEP20).
19
-
- Do no magic to your code.
25
+
- **Explicit is better than implicit (PEP20)**.
26
+
- **Do not do any magic to your code**.
20
27
21
-
How does it different from the other frameworks?
28
+
How is that different from the other frameworks?
22
29
23
30
- **No autowiring.** The framework does NOT do any autowiring / autoresolving of the dependencies. You need to specify everything explicitly. Because *"Explicit is better than implicit" (PEP20)*.
24
31
- **Does not pollute your code.** Your application does NOT know and does NOT depend on the framework. No ``@inject`` decorators, annotations, patching or any other magic tricks.
25
32
26
-
``Dependency Injector`` makes a simple contract with you:
27
-
28
-
- You tell the framework how to build you code
29
-
- The framework does it for you
30
-
31
-
The power of the ``Dependency Injector`` is in its simplicity and straightforwardness. It is a simple tool for the powerful concept.
32
-
33
-
The key features of the ``Dependency Injector`` framework are:
34
-
35
-
+ Easy, smart, and Pythonic style.
36
-
+ Does NOT pollute client code.
37
-
+ Obvious and clear structure.
38
-
+ Extensibility and flexibility.
39
-
+ High performance.
40
-
+ Memory efficiency.
41
-
+ Thread safety.
42
-
+ Documented.
43
-
+ Semantically versioned.
44
-
+ Distributed as pre-compiled wheels.
45
-
46
-
``Dependency Injector`` containers and providers are implemented as C extension
47
-
types using ``Cython``.
48
-
49
-
``Dependency Injector`` framework can be used in the different application types:
50
-
51
-
+ Web applications based on the ``Flask``, ``Django`` or any other web framework.
52
-
+ Asynchronous applications ``asyncio``, ``aiohttp``, ``Tornado``, or ``Twisted``.
53
-
+ Standalone frameworks and libraries.
54
-
+ GUI applications.
55
-
56
-
``Dependency Injector`` framework can be integrated on the different project
57
-
stages:
58
-
59
-
+ It can be used in the beginning of the development of a new application.
60
-
+ It can be integrated into application that is on its active development stage.
61
-
+ It can be used for refactoring of legacy application.
62
-
63
-
Components of ``Dependency Injector`` framework could be used:
64
-
65
-
+ In composition with each other.
66
-
+ Independently from each other.
33
+
The power of the framework is in a simplicity. ``Dependency Injector`` is a simple tool for the powerful concept.
0 commit comments