-
Notifications
You must be signed in to change notification settings - Fork 92
Closed
Description
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))
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
alecthomas commentedon Aug 17, 2015
Sure, that makes sense to me. Send a PR with tests and I'll be happy to merge it.
Letsch22 commentedon May 27, 2022
In my own projects I've been finding myself reaching for this functionality, I opened #197 to add it.
KrzysztofMadejski commentedon Mar 15, 2024
I just ran into the same need. It's quite of a gap that
multibind
can't work withClassProvider
as normalbind
would.