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

Configuration provider injects as dict instance when passing entire config as dependency

Open VStoilovskyi opened this issue 2 years ago • 0 comments

Struggling with an issue when pass providers.Configuration directly to Object. In my code I have something like global context, and I want to keep configs instance in this context directly. But when I pass providers.Configuration to context object when wiring it passes as dict instance instead of Config. Is there any way to pass Configuration instance directly or at least add this particular behavior to documentation?

Example:


class CustomContext:
    def __init__(self, config: providers.Configuration):
        self.config = config

class Container(containers.DeclarativeContainer):
    config = providers.Configuration(yaml_files=['config.yml'])

    some_context = providers.Singleton(
        CustomContext,
        config=config
    )

@inject
def init(
        some_context: CustomContext = Provide[Container.some_context]
):
    # Ex. 
    isinstance(some_context.config, dict)  # -> True 

VStoilovskyi avatar Jun 03 '22 11:06 VStoilovskyi