mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-02-16 19:40:59 +03:00
Add docs about AbstractFactory provider
This commit is contained in:
parent
f4992d842e
commit
144665ef3f
BIN
docs/images/providers/abstract_factory.png
Normal file
BIN
docs/images/providers/abstract_factory.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
|
@ -106,5 +106,43 @@ provided type:
|
||||||
:language: python
|
:language: python
|
||||||
:linenos:
|
:linenos:
|
||||||
|
|
||||||
|
Abstract factory providers
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
:py:class:`AbstractFactory` is a :py:class:`Factory` provider that must be
|
||||||
|
explicitly overridden before calling.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
Overriding of :py:class:`AbstractFactory` is possible only by another
|
||||||
|
:py:class:`Factory` provider.
|
||||||
|
|
||||||
|
:py:class:`AbstractFactory` provider is useful when it is needed to specify
|
||||||
|
explicitly that it only provides abstraction, but not an implementation.
|
||||||
|
Client code must override such factories with factories that provide particular
|
||||||
|
implementations. Otherwise, :py:class:`AbstractFactory` will raise an error
|
||||||
|
on attempt of calling it. At the same time, :py:class:`AbstractFactory` is
|
||||||
|
regular provider that could be injected into other providers (or used for
|
||||||
|
any other kind of bindings) without being overridden. After
|
||||||
|
:py:class:`AbstractFactory` provider has been overridden, its behaviour is
|
||||||
|
identical to regular :py:class:`Factory` provider.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
.. image:: /images/providers/abstract_factory.png
|
||||||
|
:width: 100%
|
||||||
|
:align: center
|
||||||
|
|
||||||
|
Listing of ``cache.py``:
|
||||||
|
|
||||||
|
.. literalinclude:: ../../examples/providers/abstract_factory/cache.py
|
||||||
|
:language: python
|
||||||
|
:linenos:
|
||||||
|
|
||||||
|
Listing of ``example.py``:
|
||||||
|
|
||||||
|
.. literalinclude:: ../../examples/providers/abstract_factory/example.py
|
||||||
|
:language: python
|
||||||
|
:linenos:
|
||||||
|
|
||||||
.. disqus::
|
.. disqus::
|
||||||
|
|
Loading…
Reference in New Issue
Block a user