mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-02-06 06:30:51 +03:00
Merge branch 'release/3.43.0' into master
This commit is contained in:
commit
0cddc4cf25
|
@ -143,7 +143,7 @@ Here comes the ``Dependency Injector``.
|
|||
What does the Dependency Injector do?
|
||||
-------------------------------------
|
||||
|
||||
With the dependency injection pattern objects lose the responsibility of assembling the
|
||||
With the dependency injection pattern objects loose the responsibility of assembling the
|
||||
dependencies. The ``Dependency Injector`` absorbs that responsibility.
|
||||
|
||||
``Dependency Injector`` helps to assemble the objects.
|
||||
|
|
|
@ -3,7 +3,7 @@ dependency_injector.ext.aiohttp
|
|||
|
||||
.. automodule:: dependency_injector.ext.aiohttp
|
||||
:members:
|
||||
:special-members:
|
||||
:show-inheritance:
|
||||
|
||||
|
||||
.. disqus::
|
||||
|
|
|
@ -3,7 +3,7 @@ dependency_injector.containers
|
|||
|
||||
.. automodule:: dependency_injector.containers
|
||||
:members:
|
||||
:special-members:
|
||||
|
||||
:inherited-members:
|
||||
:show-inheritance:
|
||||
|
||||
.. disqus::
|
||||
|
|
|
@ -3,7 +3,7 @@ dependency_injector.ext.flask
|
|||
|
||||
.. automodule:: dependency_injector.ext.flask
|
||||
:members:
|
||||
:special-members:
|
||||
:show-inheritance:
|
||||
|
||||
|
||||
.. disqus::
|
||||
|
|
|
@ -78,6 +78,7 @@ Key features of the ``Dependency Injector``:
|
|||
and dictionaries. See :ref:`configuration-provider`.
|
||||
- **Containers**. Provides declarative and dynamic containers. See :ref:`containers`.
|
||||
- **Performance**. Fast. Written in ``Cython``.
|
||||
- **Typing**. Provides typing stubs, ``mypy``-friendly.
|
||||
- **Maturity**. Mature and production-ready. Well-tested, documented and supported.
|
||||
|
||||
.. code-block:: python
|
||||
|
|
|
@ -123,7 +123,7 @@ Here comes the ``Dependency Injector``.
|
|||
What does the Dependency Injector do?
|
||||
-------------------------------------
|
||||
|
||||
With the dependency injection pattern objects lose the responsibility of assembling the
|
||||
With the dependency injection pattern objects loose the responsibility of assembling the
|
||||
dependencies. The ``Dependency Injector`` absorbs that responsibility.
|
||||
|
||||
``Dependency Injector`` helps to assemble the objects.
|
||||
|
@ -178,7 +178,7 @@ client with a mock:
|
|||
with container.api_client.override(mock.Mock()):
|
||||
service = container.service()
|
||||
|
||||
You can override any provider by another provider.
|
||||
You can override any provider with another provider.
|
||||
|
||||
It also helps you in configuring project for the different environments: replace an API client
|
||||
with a stub on the dev or stage.
|
||||
|
@ -210,7 +210,7 @@ Dependency injection brings you 3 advantages:
|
|||
- **Testability**. Testing is easy because you can easily inject mocks instead of real objects
|
||||
that use API or database, etc.
|
||||
- **Clearness and maintainability**. Dependency injection helps you reveal the dependencies.
|
||||
Implicit becomes explicit. And "Explicit is better than implicit" (PEP20 - The Zen of Python).
|
||||
Implicit becomes explicit. And "Explicit is better than implicit" (PEP 20 - The Zen of Python).
|
||||
You have all the components and dependencies defined explicitly in the container. This
|
||||
provides an overview and control on the application structure. It is easy to understand and
|
||||
change it.
|
||||
|
|
|
@ -31,7 +31,7 @@ Verification of currently installed version could be done using
|
|||
|
||||
>>> import dependency_injector
|
||||
>>> dependency_injector.__version__
|
||||
'3.38.0'
|
||||
'3.43.0'
|
||||
|
||||
.. _PyPi: https://pypi.org/project/dependency-injector/
|
||||
.. _GitHub: https://github.com/ets-labs/python-dependency-injector
|
||||
|
|
|
@ -20,6 +20,7 @@ Key features of the ``Dependency Injector``:
|
|||
and dictionaries. See :ref:`configuration-provider`.
|
||||
- **Containers**. Provides declarative and dynamic containers. See :ref:`containers`.
|
||||
- **Performance**. Fast. Written in ``Cython``.
|
||||
- **Typing**. Provides typing stubs, ``mypy``-friendly.
|
||||
- **Maturity**. Mature and production-ready. Well-tested, documented and supported.
|
||||
|
||||
The framework stands on two principles:
|
||||
|
|
|
@ -7,6 +7,12 @@ that were made in every particular version.
|
|||
From version 0.7.6 *Dependency Injector* framework strictly
|
||||
follows `Semantic versioning`_
|
||||
|
||||
3.43.0
|
||||
------
|
||||
- Update API documentation.
|
||||
- Remove not relevant "speech" example.
|
||||
- Fix a few typos.
|
||||
|
||||
3.42.0
|
||||
------
|
||||
- Update "DI in Python" documentation page.
|
||||
|
|
|
@ -24,7 +24,7 @@ It causes the cascade effect that helps to assemble object graphs. See ``Factory
|
|||
│
|
||||
└──> provider6()
|
||||
|
||||
Another providers feature is an overriding. You can override any provider by another provider.
|
||||
Another providers feature is an overriding. You can override any provider with another provider.
|
||||
This helps in testing. This also helps in overriding API clients with stubs for the development
|
||||
or staging environment. See the example at :ref:`provider-overriding`.
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ Provider overriding
|
|||
|
||||
.. currentmodule:: dependency_injector.providers
|
||||
|
||||
You can override any provider by another provider.
|
||||
You can override any provider with another provider.
|
||||
|
||||
When provider is overridden it calls to the overriding provider instead of providing
|
||||
the object by its own.
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
"""IoC container example."""
|
||||
|
||||
import collections
|
||||
|
||||
import dependency_injector.containers as containers
|
||||
import dependency_injector.providers as providers
|
||||
|
||||
|
||||
Engine = collections.namedtuple('Engine', [])
|
||||
Car = collections.namedtuple('Car', ['serial_number', 'engine'])
|
||||
|
||||
|
||||
class Container(containers.DeclarativeContainer):
|
||||
"""IoC container."""
|
||||
|
||||
engine_factory = providers.Factory(Engine)
|
||||
|
||||
car_factory = providers.Factory(Car, engine=engine_factory)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
car1 = Container.car_factory(serial_number=1)
|
||||
car2 = Container.car_factory(serial_number=2)
|
||||
|
||||
assert car1.serial_number == 1 and car2.serial_number == 2
|
||||
assert car1.engine is not car2.engine
|
|
@ -1,14 +0,0 @@
|
|||
"""Factory provider example."""
|
||||
|
||||
from dependency_injector import providers
|
||||
|
||||
|
||||
object_factory = providers.Factory(object)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
object1 = object_factory()
|
||||
object2 = object_factory()
|
||||
|
||||
assert object1 is not object2
|
||||
assert isinstance(object1, object) and isinstance(object2, object)
|
|
@ -1,20 +0,0 @@
|
|||
"""Factory provider keyword argument injections example."""
|
||||
|
||||
import collections
|
||||
|
||||
import dependency_injector.providers as providers
|
||||
|
||||
|
||||
Engine = collections.namedtuple('Engine', [])
|
||||
Car = collections.namedtuple('Car', ['serial_number', 'engine'])
|
||||
|
||||
engine_factory = providers.Factory(Engine)
|
||||
car_factory = providers.Factory(Car, engine=engine_factory)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
car1 = car_factory(serial_number=1)
|
||||
car2 = car_factory(serial_number=2)
|
||||
|
||||
assert car1.serial_number == 1 and car2.serial_number == 2
|
||||
assert car1.engine is not car2.engine
|
|
@ -1,24 +0,0 @@
|
|||
"""Overriding of factory provider example."""
|
||||
|
||||
import collections
|
||||
|
||||
import dependency_injector.providers as providers
|
||||
|
||||
|
||||
Engine = collections.namedtuple('Engine', [])
|
||||
Car = collections.namedtuple('Car', ['serial_number', 'engine'])
|
||||
|
||||
engine_factory = providers.Factory(Engine)
|
||||
car_factory = providers.Factory(Car, engine=engine_factory)
|
||||
|
||||
EngineX = collections.namedtuple('EngineX', [])
|
||||
engine_factory.override(providers.Factory(EngineX))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
car1 = car_factory(serial_number=1)
|
||||
car2 = car_factory(serial_number=2, engine=Engine())
|
||||
|
||||
assert car1.serial_number == 1 and car2.serial_number == 2
|
||||
assert car1.engine.__class__ is EngineX
|
||||
assert car2.engine.__class__ is Engine
|
|
@ -1,21 +0,0 @@
|
|||
"""@inject decorator example."""
|
||||
|
||||
from container import Container
|
||||
|
||||
from dependency_injector.injections import inject
|
||||
|
||||
|
||||
@inject(car_factory=Container.car_factory.delegate())
|
||||
@inject(extra_engine=Container.engine_factory)
|
||||
def main(car_factory, extra_engine):
|
||||
"""Run application."""
|
||||
car1 = car_factory(serial_number=1)
|
||||
car2 = car_factory(serial_number=2, engine=extra_engine)
|
||||
|
||||
assert car1.serial_number == 1 and car2.serial_number == 2
|
||||
assert car1.engine is not car2.engine
|
||||
assert car2.engine is extra_engine
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -1,7 +1,7 @@
|
|||
"""Dependency injector top-level package."""
|
||||
"""Top-level package."""
|
||||
|
||||
__version__ = '3.42.0'
|
||||
"""Version number that follows semantic versioning.
|
||||
__version__ = '3.43.0'
|
||||
"""Version number.
|
||||
|
||||
:type: str
|
||||
"""
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,7 +1,4 @@
|
|||
"""Dependency injector containers.
|
||||
|
||||
Powered by Cython.
|
||||
"""
|
||||
"""Containers module."""
|
||||
|
||||
# Declarative containers are declared as regular types because of metaclasses
|
||||
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
"""Dependency injector containers.
|
||||
|
||||
Powered by Cython.
|
||||
"""
|
||||
"""Containers module."""
|
||||
|
||||
import six
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,7 +1,4 @@
|
|||
"""Dependency injector providers.
|
||||
|
||||
Powered by Cython.
|
||||
"""
|
||||
"""Providers module."""
|
||||
|
||||
cimport cython
|
||||
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
"""Dependency injector providers.
|
||||
|
||||
Powered by Cython.
|
||||
"""
|
||||
"""Providers module."""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user