You can use reflection to collect the types. Please add a comment if you need more information about this approach (I try to avoid reflection in web apps).
EDIT
Reflection may work, but when you start using special cases it gets unreadable very fast.
When you use DI you often have situations where your class' constructor requires an object of type InterfaceX
and you want to specify which of the classes that fulfill the requirement (implement the interface) should actually be injected. Then you start to code special cases with reflection.
Using type(InterfaceX, implementedBy: Y);
is always super readable.
EDIT END
I don't know if you see this as an improvement but what we did (and I have seen in several projects)
Create more modules and add them to MyAppModule
with install
see for example at
- https://github.com/akserg/angular.dart.ui/blob/master/lib/accordion/accordion.dart
- https://github.com/akserg/angular.dart.ui/blob/master/lib/angular_ui.dart
accordion.dart
class AccordionModule extends Module {
AccordionModule() {
type(AccordionComponent);
type(AccordionHeadingComponent);
type(AccordionGroupComponent);
value(AccordionConfig, new AccordionConfig());
}
}
angular_ui.dart
class AngularUIModule extends Module {
AngularUIModule() {
install(new AlertModule());
install(new AccordionModule()); // the above module
install(new ButtonModule());
install(new CarouselModule());
install(new CollapseModule());
install(new DropdownToggleModule());
install(new ProgressbarModule());
install(new RatingModule());
install(new TabsModule());
install(new TimeoutModule());
install(new TransitionModule());
install(new ModalModule());
}
}