Skip to content

[Feature Request] Introduce Qualifiers #147

@jahermosilla

Description

@jahermosilla

It would be great to be possible to declare more than one provider bound to the same "bound_type".

Something like:

class UseCase:
    def __init__(self, some_type: SomeType):
        ...

class Dependencies(Group):
    some_type = providers.Factory(
        creator=some_creator,
        bound_type=SomeType,
        #qualifier=None # Default, the "primary"
    )

    another_type = providers.Factory(
        creator=some_another_creator,
        bound_type=SomeType,
        qualifier="another"
    )

class Usage(Group):
    my_use_case = providers.Factory(
        creator=UseCase,
    )

    some_other_use_case = providers.Factory(
        creator=UseCase,
        qualifiers={
            SomeType: "another"
        }
    )

# Resolve directly with container

container.resolve(SomeType, qualifier="another")

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