python-dependency-injector icon indicating copy to clipboard operation
python-dependency-injector copied to clipboard

Specializing the provided type using `Provider[T]` syntax

Open pembem22 opened this issue 3 years ago • 0 comments
trafficstars

Hi, recently I found out that it's possible to specialize the provided type using Provider[T] syntax. For example:

from abc import ABC
from dependency_injector import containers, providers

class AbstractClass(ABC): ...
class ImplementationClass(AbstractClass): ...

class Container(containers.DeclarativeContainer):
    service = providers.Singleton[AbstractClass](ImplementationClass)

Is this way of specializing type considered supported and is it a part of public API? If so, could you add this information to the documentation? I haven't been able to find any mention there.

pembem22 avatar Jul 22 '22 06:07 pembem22