Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

resolve a list of instances of all the derived classes of a base class #5

Open
erikash opened this issue Dec 5, 2013 · 1 comment

Comments

@erikash
Copy link

erikash commented Dec 5, 2013

Hi,
I didn't see support for this behavior... is it possible? planned feature?

An example scenario:
When bootstrapping the application, resolve an instance of all the classes derived from startable and call their start method.

@davidals
Copy link

You could do something like this:

def all_subclasses(cls):
return cls.subclasses() + [g for s in cls.subclasses() for g in all_subclasses(s)]

startables=[object_graph.provide(s) for s in all_subclasses(Startable)]
for s in startables:
s.start()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants