From cbc8d701515fb1ddaf5eb9d4ce732319c70476c6 Mon Sep 17 00:00:00 2001 From: Roman Mogilatov Date: Tue, 26 Apr 2016 13:14:39 +0300 Subject: [PATCH] Release 1.16.7 --- dependency_injector/__init__.py | 2 +- docs/introduction/di_in_python.rst | 25 +++++++++++++++++-- docs/introduction/what_is_di.rst | 20 ++------------- docs/main/changelog.rst | 4 +++ .../{car_engine_1.py => car_engine.py} | 5 ++-- .../{car_engine_2.py => car_engine_ioc.py} | 6 ++--- .../ioc_di_demos/car_engine_ioc_container.py | 19 ++++++++++++++ .../{ioc_example.py => example_ioc.py} | 0 .../ioc_di_demos/ioc_container_example.py | 19 -------------- 9 files changed, 54 insertions(+), 46 deletions(-) rename examples/ioc_di_demos/{car_engine_1.py => car_engine.py} (71%) rename examples/ioc_di_demos/{car_engine_2.py => car_engine_ioc.py} (51%) create mode 100644 examples/ioc_di_demos/car_engine_ioc_container.py rename examples/ioc_di_demos/{ioc_example.py => example_ioc.py} (100%) delete mode 100644 examples/ioc_di_demos/ioc_container_example.py diff --git a/dependency_injector/__init__.py b/dependency_injector/__init__.py index 260f7d0d..06de3b3b 100644 --- a/dependency_injector/__init__.py +++ b/dependency_injector/__init__.py @@ -61,7 +61,7 @@ from dependency_injector.errors import ( from dependency_injector import catalogs catalog = catalogs -VERSION = '1.16.5' +VERSION = '1.16.7' """Version number that follows semantic versioning. :type: str diff --git a/docs/introduction/di_in_python.rst b/docs/introduction/di_in_python.rst index 0e81c1b2..9abebe1a 100644 --- a/docs/introduction/di_in_python.rst +++ b/docs/introduction/di_in_python.rst @@ -93,7 +93,7 @@ Example Let's go through next example: -.. literalinclude:: ../../examples/ioc_di_demos/car_engine_1.py +.. literalinclude:: ../../examples/ioc_di_demos/car_engine.py :language: python :linenos: @@ -101,6 +101,27 @@ Let's go through next example: more sense then creating an ``Engine`` separatelly and then **put (inject) it into** ``Car`` when ``Car`` is being created? -.. literalinclude:: ../../examples/ioc_di_demos/car_engine_2.py +.. literalinclude:: ../../examples/ioc_di_demos/car_engine_ioc.py :language: python :linenos: + +Previous example may look more obvious and gives a chance to start getting +other benefits of dependency injection and inversion of control, but creation +of ``Car`` instances became a bit harder cause now ``Engine`` injections +should be done manually every time when ``Car`` instances are being created. + +Let's automate ``Engine`` into ``Car`` injections using *Dependency Injector*: + + +.. literalinclude:: ../../examples/ioc_di_demos/car_engine_ioc_container.py + :language: python + :linenos: + +.. note:: + + ``Components`` from previous example is an inversion of control container. + It contains a collection of component providers that could be injected + into each other. + + Assuming this, ``Components`` could be one and the only place, where + application's structure is being managed on the high level. diff --git a/docs/introduction/what_is_di.rst b/docs/introduction/what_is_di.rst index 05b9b169..7ffc060f 100644 --- a/docs/introduction/what_is_di.rst +++ b/docs/introduction/what_is_di.rst @@ -88,28 +88,12 @@ Let's go through the code of ``example.py``: :linenos: At some point, things defined above mean, that the code from ``example.py``, -could look different, like in ``ioc_example.py``: +could look different, like in ``example_ioc.py``: -.. literalinclude:: ../../examples/ioc_di_demos/ioc_example.py +.. literalinclude:: ../../examples/ioc_di_demos/example_ioc.py :language: python :linenos: -Also the code from ``ioc_example.py`` could be upgraded with inversion of -control container, like in ``ioc_container_example.py``: - -.. literalinclude:: ../../examples/ioc_di_demos/ioc_container_example.py - :language: python - :linenos: - -.. note:: - - ``Components`` from ``ioc_container_example.py`` is an IoC container. It - contains a collection of component providers that could be injected into - each other. - - Assuming this, ``Components`` could be one and the only place, where - application's structure is being managed on the high level. - Best explanation, ever ~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/main/changelog.rst b/docs/main/changelog.rst index 18078059..d9786b64 100644 --- a/docs/main/changelog.rst +++ b/docs/main/changelog.rst @@ -11,6 +11,10 @@ Development version ------------------- - No features. +1.16.7 +------ +- Add some changes into introduction section of documentation. + 1.16.5 ------ - Move project to ``https://github.com/ets-labs/python-dependency-injector``. diff --git a/examples/ioc_di_demos/car_engine_1.py b/examples/ioc_di_demos/car_engine.py similarity index 71% rename from examples/ioc_di_demos/car_engine_1.py rename to examples/ioc_di_demos/car_engine.py index bf6fde9a..44e9e5c8 100644 --- a/examples/ioc_di_demos/car_engine_1.py +++ b/examples/ioc_di_demos/car_engine.py @@ -1,4 +1,4 @@ -"""Car & Engine example 1.""" +"""Car & Engine example.""" class Engine(object): @@ -14,5 +14,4 @@ class Car(object): if __name__ == '__main__': - car = Car() - assert car.engine is not None + car = Car() # Application creates Car's instance diff --git a/examples/ioc_di_demos/car_engine_2.py b/examples/ioc_di_demos/car_engine_ioc.py similarity index 51% rename from examples/ioc_di_demos/car_engine_2.py rename to examples/ioc_di_demos/car_engine_ioc.py index 194506d0..48a9e435 100644 --- a/examples/ioc_di_demos/car_engine_2.py +++ b/examples/ioc_di_demos/car_engine_ioc.py @@ -1,4 +1,4 @@ -"""Car & Engine example 2.""" +"""Refactored Car & Engine example that demostrates inversion of control.""" class Engine(object): @@ -14,5 +14,5 @@ class Car(object): if __name__ == '__main__': - car = Car(Engine()) - assert car.engine is not None + engine = Engine() # Application creates Engine's instance + car = Car(engine) # and inject it into the Car's instance diff --git a/examples/ioc_di_demos/car_engine_ioc_container.py b/examples/ioc_di_demos/car_engine_ioc_container.py new file mode 100644 index 00000000..18fd6dd7 --- /dev/null +++ b/examples/ioc_di_demos/car_engine_ioc_container.py @@ -0,0 +1,19 @@ +"""Example of inversion of control container for Car & Engine example.""" + +from dependency_injector import catalogs +from dependency_injector import providers + +from car_engine_ioc import Car +from car_engine_ioc import Engine + + +class Components(catalogs.DeclarativeCatalog): + """Catalog of component providers.""" + + engine = providers.Factory(Engine) + + car = providers.Factory(Car, engine=engine) + + +if __name__ == '__main__': + car = Components.car() # Application creates Car's instance diff --git a/examples/ioc_di_demos/ioc_example.py b/examples/ioc_di_demos/example_ioc.py similarity index 100% rename from examples/ioc_di_demos/ioc_example.py rename to examples/ioc_di_demos/example_ioc.py diff --git a/examples/ioc_di_demos/ioc_container_example.py b/examples/ioc_di_demos/ioc_container_example.py deleted file mode 100644 index 0389aa70..00000000 --- a/examples/ioc_di_demos/ioc_container_example.py +++ /dev/null @@ -1,19 +0,0 @@ -"""The Code, that uses IoC container.""" - -from dependency_injector import catalogs -from dependency_injector import providers - -from ioc_example import Service -from ioc_example import Client - - -class Components(catalogs.DeclarativeCatalog): - """Catalog of component providers.""" - - service = providers.Factory(Service) - - client = providers.Factory(Client, service=service) - - -if __name__ == '__main__': - client = Components.client() # Application creates Client's instance