Skip to content

Attempt multi scope no deps #802

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

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions blackbox-multi-scope/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.avaje</groupId>
Expand Down Expand Up @@ -31,7 +31,11 @@
<version>1.5</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.avaje</groupId>
<artifactId>blackbox-other</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import org.multi.scope.CrossCutScope;

@CrossCutScope
public class BeanCross{
public BeanCross(final BeanInModA beanInModA, final BeanInModB beanInModB) {

}
public class BeanCross {
public BeanCross(final BeanInModA beanInModA, final BeanInModB beanInModB) {}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package org.multi.crosscut;

import org.multi.moda.BeanInModA;
import org.multi.modb.BeanInModB;
import org.multi.modc.modb.BeanInModC;
import org.multi.modc.BeanInModC;
import org.multi.scope.CrossCutScope;

@CrossCutScope
public class BeanCross2 {
public BeanCross2(final BeanInModA beanInModA, final BeanInModC beanInModC) {

}
public BeanCross2(final BeanInModA beanInModA, final BeanInModC beanInModC) {}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package org.multi.crosscut;

import org.multi.modc.modb.COther;
import org.multi.modc.COther;
import org.multi.scope.CrossCutScope;

@CrossCutScope
public class BeanCross3 {
public BeanCross3(final COther other) {

}
public BeanCross3(final COther other) {}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package org.multi.main;

import io.avaje.inject.BeanScope;
import org.multi.crosscut.BeanCross;
import org.multi.crosscut.BeanCross2;
import org.multi.crosscut.BeanCross3;
import org.multi.crosscut.CrossCutModule;
import org.multi.moda.BeanInModA;
import org.multi.moda.ModAModule;
import org.multi.modb.BeanInModB;
import org.multi.modb.ModBModule;
import org.multi.modc.modb.ModCModule;

import io.avaje.inject.BeanScope;

public class CrossCutMain {

Expand All @@ -24,8 +22,6 @@ public static void main(String[] args) {
}

public static BeanScope buildScope() {
return BeanScope.builder()
.modules(new ModAModule(), new ModCModule(), new ModBModule(), new CrossCutModule())
.build();
return BeanScope.builder().modules(CrossCutModule.allRequiredModules()).build();
}
}
19 changes: 19 additions & 0 deletions blackbox-multi-scope/src/main/java/org/multi/many/BeanInMany.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.multi.many;

import org.multi.moda.BeanInModA;
import org.multi.modc.COther;
import org.multi.mode.BeanInModE;
import org.multi.scope.ManyScope;
import org.other.one.custom.OtherCustomComponent;

import io.avaje.inject.External;

@ManyScope
public class BeanInMany {

public BeanInMany(
BeanInModE beanInModE,
COther cOther,
BeanInModA modA,
@External OtherCustomComponent external) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
import org.multi.scope.ModAScope;

@ModAScope
public class BeanInModA {
}
public class BeanInModA {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.multi.modb;

import org.multi.modc.modb.COther;
import org.multi.modc.COther;
import org.multi.scope.ModBScope;

@ModBScope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
import org.multi.scope.ModBScope;

@ModBScope
public class BeanInModB {
}
public class BeanInModB {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.multi.modc;

import org.multi.scope.ModCScope;

@ModCScope
public class BeanInModC {}
6 changes: 6 additions & 0 deletions blackbox-multi-scope/src/main/java/org/multi/modc/COther.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.multi.modc;

import org.multi.scope.ModCScope;

@ModCScope
public class COther {}

This file was deleted.

This file was deleted.

14 changes: 14 additions & 0 deletions blackbox-multi-scope/src/main/java/org/multi/modd/BeanInModD.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.multi.modd;

import org.multi.moda.BeanInModA;
import org.multi.scope.ModDScope;

@ModDScope
public class BeanInModD {

private final BeanInModA beanA;

public BeanInModD(final BeanInModA beanInModA) {
this.beanA = beanInModA;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.multi.mode;

import org.multi.scope.ModEScope;

@ModEScope
public class BeanInModE {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import io.avaje.inject.InjectModule;
import jakarta.inject.Scope;
import org.multi.modb.BeanInModB;

@Scope
@InjectModule(requires = {ModAScope.class, ModBScope.class}, strictWiring = true)
public @interface CrossCutScope {
}
@InjectModule(requires = {ModAScope.class, ModBScope.class})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These being modules or scopes is a hard one by the looks:

  • If they are modules, then we don't need to add to the autoProvides (although it works without this PR without doing that 🤔 )
  • If they are scopes, you can easily find the scopes they rely on

But then, either way, it (currently) falls down when you attempt to extract the module dependencies to build the method... So maybe having them as modules is better? Although then you may be trying to read something from the annotation that doesn't yet exist and I've ran into that before as a problem in another project...

Copy link
Collaborator

@SentryMan SentryMan Apr 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so modules in the annotation doesn't fly because the module classes don't exist by the time the processor tries to read them

public @interface CrossCutScope {}
11 changes: 11 additions & 0 deletions blackbox-multi-scope/src/main/java/org/multi/scope/ManyScope.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.multi.scope;

import org.other.one.custom.ExternalScope;

import io.avaje.inject.InjectModule;
import jakarta.inject.Scope;

@Scope
@InjectModule(
requires = {ExternalScope.class, ModDScope.class, CrossCutScope.class, ModEScope.class})
public @interface ManyScope {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
import jakarta.inject.Scope;

@Scope
@InjectModule(strictWiring = true)
public @interface ModAScope {
}
@InjectModule
public @interface ModAScope {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
import jakarta.inject.Scope;

@Scope
@InjectModule(requires = ModCScope.class, strictWiring = true)
public @interface ModBScope {
}
@InjectModule(requires = ModCScope.class)
public @interface ModBScope {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
import jakarta.inject.Scope;

@Scope
@InjectModule(strictWiring = true)
public @interface ModCScope {
}
@InjectModule
public @interface ModCScope {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.multi.scope;

import io.avaje.inject.InjectModule;
import jakarta.inject.Scope;

@Scope
@InjectModule(requires = {ModAScope.class})
public @interface ModDScope {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.multi.scope;

import io.avaje.inject.InjectModule;
import jakarta.inject.Scope;

@Scope
@InjectModule
public @interface ModEScope {}
Original file line number Diff line number Diff line change
@@ -1,24 +1,64 @@
package org.multi.crosscut;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertTrue;

import io.avaje.inject.BeanScope;
import org.junit.jupiter.api.Test;
import org.multi.many.BeanInMany;
import org.multi.many.ManyModule;
import org.multi.moda.BeanInModA;
import org.multi.moda.ModAModule;
import org.multi.modb.BOther;
import org.multi.modb.BeanInModB;
import org.multi.modb.ModBModule;
import org.multi.modc.BeanInModC;
import org.multi.modc.COther;
import org.multi.modc.ModCModule;
import org.multi.modd.BeanInModD;
import org.multi.modd.ModDModule;
import org.multi.mode.BeanInModE;
import org.multi.mode.ModEModule;
import org.other.one.custom.ExternalModule;

import static org.assertj.core.api.Assertions.assertThat;
import io.avaje.inject.BeanScope;

class BeanCrossTest {

@Test
void bootstrap() {
private static final Class<?>[] CHECKABLE = {
BeanCross.class,
BeanCross2.class,
BeanCross3.class,
BeanInMany.class,
BeanInModA.class,
BeanInModB.class,
BOther.class,
BeanInModC.class,
COther.class,
BeanInModD.class,
BeanInModE.class
};

try (BeanScope beanScope = BeanScope.builder()
// .modules(new CrossCutModule())
.build()) {
@Test
void testCustomOrdering() {

// var beanInModB = beanScope.get(BeanInModB.class);
// assertThat(beanInModB).isNotNull();
try (BeanScope beanScope =
assertDoesNotThrow(
() ->
BeanScope.builder()
.modules(
new ModEModule(),
new ModBModule(),
new ModDModule(),
new ManyModule(),
new ModCModule(),
new ModAModule(),
new CrossCutModule(),
new ExternalModule())
.build())) {
for (final Class<?> clazz : CHECKABLE) {
assertTrue(
beanScope.getOptional(clazz).isPresent(), "Bean not found: " + clazz.getSimpleName());
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.other.one.custom;

import io.avaje.inject.InjectModule;
import jakarta.inject.Scope;

@Scope
@InjectModule
public @interface ExternalScope {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.other.one.custom;

@ExternalScope
public class OtherCustomComponent {}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
ProcessingContext.registerProvidedTypes(moduleFileProvided);
moduleData.forEach(ProcessingContext::addModule);
this.elementUtils = processingEnv.getElementUtils();
this.allScopes = new AllScopes();
this.allScopes = ProcessingContext.allScopes();
this.defaultScope = allScopes.defaultScope();
ExternalProvider.registerPluginProvidedTypes(defaultScope);
pluginFileProvided.forEach(defaultScope::pluginProvided);
Expand Down
Loading