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

[Feature request] Config provider type/converter specification/declaration

Open artem30801 opened this issue 3 years ago • 2 comments

Currently, I see only two ways to specify value types when loading configuration provider from file:

  1. To declare additional provider with value conversion
  2. 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 as default 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

artem30801 avatar Jul 05 '21 12:07 artem30801

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.

jochenparm avatar Jul 12 '21 11:07 jochenparm

Thanks for the feedback @artem30801 and @jochenparm . Will think on improving this.

rmk135 avatar Jul 12 '21 11:07 rmk135