diff --git a/docs/images/providers/factory_delegation.png b/docs/images/providers/factory_delegation.png index 3aa65279..28703c76 100644 Binary files a/docs/images/providers/factory_delegation.png and b/docs/images/providers/factory_delegation.png differ diff --git a/docs/providers/factory.rst b/docs/providers/factory.rst index 8d39728c..3a42d780 100644 --- a/docs/providers/factory.rst +++ b/docs/providers/factory.rst @@ -105,20 +105,20 @@ Example: Factory providers delegation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -``Factory`` provider could be delegated to any other provider via any kind of -injection. Saying in other words, delegation of factories - is a way to inject -factories themselves, instead of results of their calls. +``di.Factory`` provider could be delegated to any other provider via any kind +of injection. As it was mentioned earlier, if ``di.Factory`` is injectable +value, it will be called every time when injection is done. ``di.Factory`` +delegation is performed by wrapping delegated ``di.Factory`` into special +provider type - ``di.Delegate``, that just returns wrapped ``di.Factory``. +Saying in other words, delegation of factories - is a way to inject factories +themselves, instead of results of their calls. -As it was mentioned earlier, ``Injection`` calls ``Factory`` if ``Factory`` is -injectable value. ``Factory`` delegation is performed by wrapping delegated -``Factory`` into special provider type - ``Delegate``, that just returns -``Factory`` itself. Actually, there are two ways of creating factory delegates: -+ ``Delegate(Factory(...))`` - obviously wrapping factory into ``Delegate`` - provider. -+ ``Factory(...).delegate()`` - calling factory ``delegate()`` method, that ++ ``di.Delegate(di.Factory(...))`` - obviously wrapping factory into + ``di.Delegate`` provider. ++ ``di.Factory(...).delegate()`` - calling factory ``delegate()`` method, that returns delegate wrapper for current factory. Example: diff --git a/examples/providers/factory_delegation.py b/examples/providers/factory_delegation.py index 4715077f..f878f6f0 100644 --- a/examples/providers/factory_delegation.py +++ b/examples/providers/factory_delegation.py @@ -1,7 +1,6 @@ -"""`Factory` providers delegation example.""" +"""`di.Factory` providers delegation example.""" -from dependency_injector.providers import Factory -from dependency_injector.injections import KwArg +import dependency_injector as di class User(object): @@ -11,7 +10,7 @@ class User(object): def __init__(self, photos_factory): """Initializer. - :param photos_factory: (dependency_injector.providers.Factory) -> Photo + :param photos_factory: (di.Factory) -> Photo """ self.photos_factory = photos_factory self._main_photo = None @@ -30,9 +29,9 @@ class Photo(object): """Example class Photo.""" # User and Photo factories: -photos_factory = Factory(Photo) -users_factory = Factory(User, - KwArg('photos_factory', photos_factory.delegate())) +photos_factory = di.Factory(Photo) +users_factory = di.Factory(User, + photos_factory=di.Delegate(photos_factory)) # Creating several User objects: user1 = users_factory()