Add container base class

This commit is contained in:
Roman Mogylatov 2021-02-03 15:33:16 -05:00
parent 6cc1a0c61f
commit cba5aefd65
6 changed files with 1484 additions and 1417 deletions

View File

@ -7,6 +7,13 @@ that were made in every particular version.
From version 0.7.6 *Dependency Injector* framework strictly From version 0.7.6 *Dependency Injector* framework strictly
follows `Semantic versioning`_ follows `Semantic versioning`_
Development version
-------------------
- Add container base class ``containers.Container``. ``DynamicContainer``
and ``DeclarativeContainer`` become subclasses of the ``Container``.
See issue: `#386 <https://github.com/ets-labs/python-dependency-injector/issues/386>`_.
Thanks to `@ventaquil <https://github.com/ventaquil>`_ for reporting the issue.
4.15.0 4.15.0
------ ------
- Add ``Configuration.from_pydantic()`` method to load configuration from a ``pydantic`` settings. - Add ``Configuration.from_pydantic()`` method to load configuration from a ``pydantic`` settings.

File diff suppressed because it is too large Load Diff

View File

@ -23,7 +23,11 @@ else:
raise NotImplementedError('Wiring requires Python 3.6 or above') raise NotImplementedError('Wiring requires Python 3.6 or above')
class DynamicContainer(object): class Container(object):
"""Abstract container."""
class DynamicContainer(Container):
"""Dynamic inversion of control container. """Dynamic inversion of control container.
.. code-block:: python .. code-block:: python
@ -370,7 +374,7 @@ class DeclarativeContainerMetaClass(type):
@six.add_metaclass(DeclarativeContainerMetaClass) @six.add_metaclass(DeclarativeContainerMetaClass)
class DeclarativeContainer(object): class DeclarativeContainer(Container):
"""Declarative inversion of control container. """Declarative inversion of control container.
.. code-block:: python .. code-block:: python

View File

@ -48,3 +48,11 @@ class Container5(containers.DeclarativeContainer):
dependencies: Dict[str, providers.Provider] = Container5.dependencies dependencies: Dict[str, providers.Provider] = Container5.dependencies
# Test 6: to check base class
class Container6(containers.DeclarativeContainer):
provider = providers.Factory(int)
container6: containers.Container = Container6()

View File

@ -22,3 +22,6 @@ container4.set_providers(a=providers.Provider())
# Test 5: to check .dependencies attribute # Test 5: to check .dependencies attribute
container5 = containers.DynamicContainer() container5 = containers.DynamicContainer()
dependencies: Dict[str, providers.Provider] = container5.dependencies dependencies: Dict[str, providers.Provider] = container5.dependencies
# Test 6: to check base class
container6: containers.Container = containers.DynamicContainer()

View File

@ -0,0 +1,18 @@
import unittest
from dependency_injector import containers
class SomeClass:
...
class TypesTest(unittest.TestCase):
def test_declarative(self):
container: containers.Container = containers.DeclarativeContainer()
self.assertIsInstance(container, containers.Container)
def test_dynamic(self):
container: containers.Container = containers.DynamicContainer()
self.assertIsInstance(container, containers.Container)