Skip to content

Commit

Permalink
Merge a40b380 into 38ca1cd
Browse files Browse the repository at this point in the history
  • Loading branch information
rmk135 committed Jan 31, 2022
2 parents 38ca1cd + a40b380 commit 6e056ee
Show file tree
Hide file tree
Showing 15 changed files with 10,021 additions and 8,754 deletions.
4 changes: 4 additions & 0 deletions docs/main/changelog.rst
Expand Up @@ -21,6 +21,10 @@ Development version
``FactoryAggregate.factories`` attribute.
- Add ``.set_providers()`` method to the ``FactoryAggregate`` provider. It is an alias for
``FactoryAggregate.set_factories()`` method.
- Add string imports for ``Factory``, ``Singleton``, ``Callable``, ``Resource``, and ``Coroutine``
providers, e.g. ``Factory("module.Class")``.
See issue `#531 <https://github.com/ets-labs/python-dependency-injector/issues/531>`_.
Thanks to `@al-stefanitsky-mozdor <https://github.com/al-stefanitsky-mozdor>`_ for suggesting the feature.
- Fix ``Dependency`` provider to don't raise "Dependency is not defined" error when the ``default``
is a falsy value of proper type.
See issue `#550 <https://github.com/ets-labs/python-dependency-injector/issues/550>`_. Thanks to
Expand Down
39 changes: 39 additions & 0 deletions docs/providers/factory.rst
Expand Up @@ -110,6 +110,45 @@ attribute of the provider that you're going to inject.

.. note:: Any provider has a ``.provider`` attribute.

.. _factory-string-imports:

String imports
--------------

``Factory`` provider can handle string imports:

.. code-block:: python
class Container(containers.DeclarativeContainer):
service = providers.Factory("myapp.mypackage.mymodule.Service")
You can also make a relative import:

.. code-block:: python
# in myapp/container.py
class Container(containers.DeclarativeContainer):
service = providers.Factory(".mypackage.mymodule.Service")
or import a member of the current module just specifying its name:

.. code-block:: python
class Service:
...
class Container(containers.DeclarativeContainer):
service = providers.Factory("Service")
.. note::
``Singleton``, ``Callable``, ``Resource``, and ``Coroutine`` providers handle string imports
the same way as a ``Factory`` provider.

.. _factory-specialize-provided-type:

Specializing the provided type
Expand Down

0 comments on commit 6e056ee

Please sign in to comment.