Skip to content

Multibinder requires instances. #45

@richburdon

Description

@richburdon

I often use multi-binding where I want to use DI to create instances of the sequence -- hence I can't bind instances directly to the sequence key. My workaround is the utility class below, but it feels like this should be built into the framework (esp. since ListOfProviders is markes @Private)

binder.multibind(Test.SEQ_KEY, ClassProviderList([MyClass])) # Not an instance.

class ClassProviderList(ListOfProviders):
    def __init__(self, classes):
        super(ClassProviderList, self).__init__()
        for cls in classes:
            self.append(ClassProvider(cls))

Activity

alecthomas

alecthomas commented on Aug 17, 2015

@alecthomas
Collaborator

Sure, that makes sense to me. Send a PR with tests and I'll be happy to merge it.

Letsch22

Letsch22 commented on May 27, 2022

@Letsch22

In my own projects I've been finding myself reaching for this functionality, I opened #197 to add it.

KrzysztofMadejski

KrzysztofMadejski commented on Mar 15, 2024

@KrzysztofMadejski

I just ran into the same need. It's quite of a gap that multibind can't work with ClassProvider as normal bind would.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @alecthomas@KrzysztofMadejski@richburdon@Letsch22

      Issue actions

        Multibinder requires instances. · Issue #45 · python-injector/injector