Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multibinder requires instances. #45

Closed
richburdon opened this issue Aug 16, 2015 · 3 comments · May be fixed by #197
Closed

Multibinder requires instances. #45

richburdon opened this issue Aug 16, 2015 · 3 comments · May be fixed by #197

Comments

@richburdon
Copy link

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))
@alecthomas
Copy link
Collaborator

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

@Letsch22
Copy link

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

@KrzysztofMadejski
Copy link

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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants