mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-24 18:43:58 +03:00
Add container base class
This commit is contained in:
parent
6cc1a0c61f
commit
cba5aefd65
|
@ -7,6 +7,13 @@ that were made in every particular version.
|
|||
From version 0.7.6 *Dependency Injector* framework strictly
|
||||
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
|
||||
------
|
||||
- Add ``Configuration.from_pydantic()`` method to load configuration from a ``pydantic`` settings.
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -23,7 +23,11 @@ else:
|
|||
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.
|
||||
|
||||
.. code-block:: python
|
||||
|
@ -370,7 +374,7 @@ class DeclarativeContainerMetaClass(type):
|
|||
|
||||
|
||||
@six.add_metaclass(DeclarativeContainerMetaClass)
|
||||
class DeclarativeContainer(object):
|
||||
class DeclarativeContainer(Container):
|
||||
"""Declarative inversion of control container.
|
||||
|
||||
.. code-block:: python
|
||||
|
|
|
@ -48,3 +48,11 @@ class Container5(containers.DeclarativeContainer):
|
|||
|
||||
|
||||
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()
|
||||
|
|
|
@ -22,3 +22,6 @@ container4.set_providers(a=providers.Provider())
|
|||
# Test 5: to check .dependencies attribute
|
||||
container5 = containers.DynamicContainer()
|
||||
dependencies: Dict[str, providers.Provider] = container5.dependencies
|
||||
|
||||
# Test 6: to check base class
|
||||
container6: containers.Container = containers.DynamicContainer()
|
||||
|
|
18
tests/unit/containers/test_types_py36.py
Normal file
18
tests/unit/containers/test_types_py36.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user