ets-labs / python-dependency-injector

Dependency injection framework for Python
https://python-dependency-injector.ets-labs.org/
BSD 3-Clause "New" or "Revised" License
3.99k stars 305 forks source link

Do I should use the Configuration provider? #738

Open NiKuma0 opened 1 year ago

NiKuma0 commented 1 year ago

This code works pretty well:

class Settings(BaseSettings):
    ...

class Container(containers.DeclarativeContainer):
    config = providers.Singleton(Settings)
    ...

I used pydantic settings, but I think this example can be used for any other settings library.

But providers.Confinguration has the from_pydantic method (and many other integration methods), for what? Should I use it instead of the Singleton provider? I just want to know the best practice and would appreciate any explanation)