python-dependency-injector
python-dependency-injector copied to clipboard
Expand kwargs from configuration provider?
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).
@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.