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

Expand kwargs from configuration provider?

Open jacquelinegarrahan opened this issue 3 years ago • 1 comments
trafficstars

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).

jacquelinegarrahan avatar Jun 28 '22 22:06 jacquelinegarrahan

@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.

rusmux avatar Mar 26 '23 20:03 rusmux