diff --git a/docs/main/introduction/di_in_python.rst b/docs/main/introduction/di_in_python.rst index 0efb1be7..c0f3f0e9 100644 --- a/docs/main/introduction/di_in_python.rst +++ b/docs/main/introduction/di_in_python.rst @@ -1,6 +1,9 @@ Dependency injection and inversion of control in Python ------------------------------------------------------- +History +~~~~~~~ + Originally, dependency injection pattern got popular in languages with static typing, like Java. Dependency injection framework can significantly improve flexibility of the language with static typing. Also, @@ -14,6 +17,9 @@ for Java. Also there is a meaning that dependency injection framework is something that Python developer would not ever need, cause dependency injection could be implemented easily using language fundamentals. +Discussion +~~~~~~~~~~ + It is true. Partly. @@ -75,6 +81,9 @@ Main design purposes of using inversion of control are: instead rely on contracts. + To prevent side effects when replacing a module. +Example +~~~~~~~ + Let's go through next example: .. literalinclude:: ../../../examples/ioc_demo/car_engine_1.py diff --git a/docs/main/introduction/structure.rst b/docs/main/introduction/structure.rst index d9a55f72..99fff8fd 100644 --- a/docs/main/introduction/structure.rst +++ b/docs/main/introduction/structure.rst @@ -8,35 +8,37 @@ interaction between each other. :width: 100% :align: center -There are 3 main entities: - -.. glossary:: - - Providers - Providers are strategies of accesing objects. For example, - :py:class:`dependency_injector.providers.Factory` creates new instance - of provided class every time it is called. - :py:class:`dependency_injector.providers.Singleton` creates provided - instance once and returns it on every next call. Providers could be - injected into each other. Providers could be overridden by another - providers. Base class is - - :py:class:`dependency_injector.providers.Provider`. - - Injections - Injections are instructions for making dependency injections - (there are several ways how they could be done). Injections are used - mostly by :py:class:`dependency_injector.providers.Factory` and - :py:class:`dependency_injector.providers.Singleton` providers, but - these are not only cases. Base class is - - :py:class:`dependency_injector.injections.Injection`. - - Catalogs - Catalogs are collections of providers. They are used for grouping - of providers by some principles. Base class is - - :py:class:`dependency_injector.catalogs.DeclarativeCatalog`. - -Some general principles about *Dependency Injector* entities: +There are 3 main entities: providers, injections and catalogs. + All of the entities could be used in composition with each other or separatelly. + Each of the entities could be extended via specialization. + +Providers +~~~~~~~~~ + +Providers are strategies of accesing objects. For example, +:py:class:`dependency_injector.providers.Factory` creates new instance +of provided class every time it is called. +:py:class:`dependency_injector.providers.Singleton` creates provided +instance once and returns it on every next call. Providers could be +injected into each other. Providers could be overridden by another +providers. Base class is - +:py:class:`dependency_injector.providers.Provider`. + +Injections +~~~~~~~~~~ + +Injections are instructions for making dependency injections +(there are several ways how they could be done). Injections are used +mostly by :py:class:`dependency_injector.providers.Factory` and +:py:class:`dependency_injector.providers.Singleton` providers, but +these are not only cases. Base class is - +:py:class:`dependency_injector.injections.Injection`. + +Catalogs +~~~~~~~~~ + +Catalogs are collections of providers. They are used for grouping +of providers by some principles. Base class is - +:py:class:`dependency_injector.catalogs.DeclarativeCatalog`. diff --git a/examples/di_demo/di_example.py b/examples/di_demo/di_example.py index 75224b7b..211ed658 100644 --- a/examples/di_demo/di_example.py +++ b/examples/di_demo/di_example.py @@ -8,9 +8,7 @@ class Components(catalogs.DeclarativeCatalog): """Components catalog.""" service = providers.Factory(Service) - - client = providers.Factory(Client, - service=service) + client = providers.Factory(Client, service=service) if __name__ == '__main__':