diff --git a/docs/images/providers/custom_provider.png b/docs/images/providers/custom_provider.png index a64b0b37..784c90bd 100644 Binary files a/docs/images/providers/custom_provider.png and b/docs/images/providers/custom_provider.png differ diff --git a/docs/providers/custom.rst b/docs/providers/custom.rst index 26d27153..2d5374e8 100644 --- a/docs/providers/custom.rst +++ b/docs/providers/custom.rst @@ -5,27 +5,23 @@ List of *Dependency Injector* providers could be widened with custom providers. Below are some tips and recommendations that have to be met: - 1. Every custom provider has to extend base provider class - - ``dependency_injector.providers.Provider``. + 1. Every custom provider has to extend base provider class - + ``di.Provider``. 2. Cusom provider's ``__init__()`` could be overriden with only condition: - parent initializer - (``dependency_injector.providers.Provider.__init__()``) has to be called. + parent initializer (``di.Provider.__init__()``) has to be called. 3. Providing strategy has to be implemented in custom provider's ``_provide()`` method. All ``*args`` & ``**kwargs`` that will be - recieved by ``dependency_injector.providers.Provider.__call__()`` will be - transefed - to custom provider's ``_provide()``. + recieved by ``di.Provider.__call__()`` will be transefed to custom + provider's ``_provide()``. 4. If custom provider is based on some standard providers, it is better to use delegation of standard providers, then extending of them. 5. If custom provider defines any attributes, it is good to list them in ``__slots__`` attribute (as *Dependency Injector* does). It can save some memory. - 6. If custom provider deals with injections (e.g. ``Factory``, - ``Singleton`` providers), it is strongly recommended to use - ``dependency_injector.injections.Injection`` and its subclasses: - ``dependency_injector.injections.KwArg``, - ``dependency_injector.injections.Attribute`` and - ``dependency_injector.injections.Method``. + 6. If custom provider deals with injections (e.g. ``di.Factory``, + ``di.Singleton`` providers), it is strongly recommended to be + consistent with ``di.Factory``, ``di.Singleton`` and ``di.Callable`` + providers style. Example: diff --git a/examples/providers/custom_factory.py b/examples/providers/custom_factory.py index b62306bd..d1e6cbf1 100644 --- a/examples/providers/custom_factory.py +++ b/examples/providers/custom_factory.py @@ -1,7 +1,6 @@ -"""Custom `Factory` example.""" +"""Custom `di.Factory` example.""" -from dependency_injector.providers import Provider -from dependency_injector.providers import Factory +import dependency_injector as di class User(object): @@ -9,7 +8,7 @@ class User(object): """Example class User.""" -class UsersFactory(Provider): +class UsersFactory(di.Provider): """Example users factory.""" @@ -17,7 +16,7 @@ class UsersFactory(Provider): def __init__(self): """Initializer.""" - self._factory = Factory(User) + self._factory = di.Factory(User) super(UsersFactory, self).__init__() def _provide(self, *args, **kwargs):