python-dependency-injector
python-dependency-injector copied to clipboard
[Feature request] Config provider type/converter specification/declaration
Currently, I see only two ways to specify value types when loading configuration provider from file:
- To declare additional provider with value conversion
- To convert value each time it used in Provide, like
Provide[Container.config.port.as_int()]
, which leads to repetition and pain when you need to change value type In my opinion, both ways do not take advantage of declarative approach for configs I propose folloving solution/feature - type specification, declared as kwarg (nested dict) in providers.Configuration initialization, same way asdefault
kwarg, where each value is either type or callable that performs conversion during config loading process. Example syntax:
config = providers.Configuration(specification={"port": int, "bind": bool_converter_func})
Would be grateful for feedback or alternative approaches I missed
I would also love better type hint integration, it allows for a more modern Python style of implementation. I prefer your framework over Lagom, but that one is really tempting to use because of the 'typing first' approach to wiring.
Thanks for the feedback @artem30801 and @jochenparm . Will think on improving this.