Skip to content

Commit e096626

Browse files
committed
#30 - More intuitive multi-module ordering for 'only supplies' modules
1 parent d4110d7 commit e096626

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/main/java/io/dinject/BootContext.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ static class FactoryOrder {
498498
private final Set<String> moduleNames = new LinkedHashSet<>();
499499
private final List<BeanContextFactory> factories = new ArrayList<>();
500500
private final List<FactoryState> queue = new ArrayList<>();
501+
private final List<FactoryState> queueNoDependencies = new ArrayList<>();
501502

502503
private final Map<String, FactoryList> providesMap = new HashMap<>();
503504

@@ -518,7 +519,13 @@ void add(BeanContextFactory factory) {
518519
}
519520
}
520521
if (isEmpty(factory.getDependsOn())) {
521-
push(wrappedFactory);
522+
if (!isEmpty(factory.getProvides())) {
523+
// only has 'provides' so we can push this
524+
push(wrappedFactory);
525+
} else {
526+
// hold until after all the 'provides only' modules are added
527+
queueNoDependencies.add(wrappedFactory);
528+
}
522529
} else {
523530
// queue it to process by dependency ordering
524531
queue.add(wrappedFactory);
@@ -550,6 +557,11 @@ private void push(FactoryState factory) {
550557
* Order the factories returning the ordered list of module names.
551558
*/
552559
Set<String> orderFactories() {
560+
// push the 'no dependency' modules after the 'provides only' ones
561+
// as this is more intuitive for the simple (only provides modules case)
562+
for (FactoryState factoryState : queueNoDependencies) {
563+
push(factoryState);
564+
}
553565
processQueue();
554566
return moduleNames;
555567
}

0 commit comments

Comments
 (0)