Skip to content

Getting a dependency group from a config string #975

Description

@Skr1pee

I’m trying to get a group of dependencies based on a string in the configuration. However, no matter what I try—using the built-in providers and selectors for this—in the final class I still end up with a provider instead of a dependency. What am I doing wrong? (An example is shown in the code below.)

class SomeValue():
    ...


class SomeClass():
    def __init__(self, v) -> None:
        assert not isinstance(v, Factory)  # Goal: pass it
        ...


class SomeValueContainer(DeclarativeContainer):
    value = Factory(SomeValue)


class MasterContainer(DeclarativeContainer):
    config = Configuration()

    value = Selector(
        config.x,
        b=Container(SomeValueContainer)
    )

    factory = Factory(SomeClass, v=value.provided.value.provided)


container = MasterContainer()
container.config.from_dict({"x": "b"})
container.factory()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions