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.9k stars 304 forks source link

Expand kwargs from configuration provider? #599

Open jacquelinegarrahan opened 2 years ago

jacquelinegarrahan commented 2 years ago

I am wondering if there is a way to communicate a config substructure as kwargs to a provider:

from dependency_injector import containers, providers
from lume_services.services.data.models.db.mysql import MySQLModelDBConfig

class Context(containers.DeclarativeContainer):
    config = providers.Configuration()

    model_db_config = providers.Singleton(
            MySQLModelDBConfig,
            **config.model_db
    )

The above raises: dependency_injector.providers.ConfigurationOption.keys() returned a non-iterable (type NoneType).

rusmux commented 1 year ago

@rmk135 I'm interested in this too. Is it possible to provide configurations as kwargs without specifying argument names? Currently, any service I want to write can only have one argument config otherwise I have to pass all arguments manually. As a workaround one can write a wrapper with config argument for every function, but that's not very convenient either.