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

Configuration object is a dictionary and not an object with which the dot notation could be used to access its elements

Open Zevrap-81 opened this issue 1 year ago • 1 comments
trafficstars

I cannot figure out why the config is a dictionary, while in every example it is an object with "." (dot) operator to access its variables.

Here is a simple code that I used:

from dependency_injector import containers, providers
from dependency_injector.wiring import Provide, inject


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


@inject
def use_config(config: providers.Configuration = Provide[Container.config]):
    print(type(config))
    print(config)



if __name__ == "__main__":
    container = Container()
    container.config.from_yaml("config.yaml")
    container.wire(modules=[__name__])

    use_config()

and the type is a 'dict'

Zevrap-81 avatar Sep 02 '24 12:09 Zevrap-81