mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-21 17:16:46 +03:00
Explicitly mention the required usage of "memo" (#598)
This commit is contained in:
parent
88a2b96102
commit
6f491a6cae
|
@ -16,8 +16,8 @@ To create a custom provider you need to follow these rules:
|
||||||
1. New provider class should inherit :py:class:`Provider`.
|
1. New provider class should inherit :py:class:`Provider`.
|
||||||
2. You need to implement the ``Provider._provide()`` method.
|
2. You need to implement the ``Provider._provide()`` method.
|
||||||
3. You need to implement the ``Provider.__deepcopy__()`` method. It should return an
|
3. You need to implement the ``Provider.__deepcopy__()`` method. It should return an
|
||||||
equivalent copy of a provider. All providers must be copied with a ``deepcopy()`` function
|
equivalent copy of a provider. All providers must be copied with the ``deepcopy()`` function
|
||||||
from the ``providers`` module. After the a new provider object is created use
|
from the ``providers`` module. It's essential to pass ``memo`` into ``deepcopy`` in order to keep the preconfigured ``args`` and ``kwargs`` of stored providers. After the a new provider object is created, use
|
||||||
``Provider._copy_overriding()`` method to copy all overriding providers. See the example
|
``Provider._copy_overriding()`` method to copy all overriding providers. See the example
|
||||||
below.
|
below.
|
||||||
4. If new provider has a ``__init__()`` method, it should call the parent
|
4. If new provider has a ``__init__()`` method, it should call the parent
|
||||||
|
@ -33,7 +33,7 @@ To create a custom provider you need to follow these rules:
|
||||||
.. note::
|
.. note::
|
||||||
1. Prefer delegation over inheritance. If you choose between inheriting a ``Factory`` or
|
1. Prefer delegation over inheritance. If you choose between inheriting a ``Factory`` or
|
||||||
inheriting a ``Provider`` and use ``Factory`` internally - the last is better.
|
inheriting a ``Provider`` and use ``Factory`` internally - the last is better.
|
||||||
2. When create a new provider follow the ``Factory``-like injections style. Consistency matters.
|
2. When creating a new provider follow the ``Factory``-like injections style. Consistency matters.
|
||||||
3. Use the ``__slots__`` attribute to make sure nothing could be attached to your provider. You
|
3. Use the ``__slots__`` attribute to make sure nothing could be attached to your provider. You
|
||||||
will also save some memory.
|
will also save some memory.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user