-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dirk-di module with Dirk flavored injector configuration
- Loading branch information
Showing
10 changed files
with
1,176 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
dirk-annotations/src/main/java/org/int4/dirk/annotations/Any.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.int4.dirk.annotations; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import jakarta.inject.Qualifier; | ||
|
||
/** | ||
* The any qualifier type. | ||
* | ||
* <p>Every candidate automatically gets this qualifier. | ||
*/ | ||
@Qualifier | ||
@Documented | ||
@Retention(RUNTIME) | ||
@Target({TYPE, METHOD, PARAMETER, FIELD}) | ||
public @interface Any { | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
dirk-annotations/src/main/java/org/int4/dirk/annotations/Default.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.int4.dirk.annotations; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import jakarta.inject.Qualifier; | ||
|
||
/** | ||
* The default qualifier type. | ||
* | ||
* <p>When a candidate or dependency does not specify any qualifier, they will automatically have the | ||
* qualifier {@code Default}. | ||
*/ | ||
@Qualifier | ||
@Documented | ||
@Retention(RUNTIME) | ||
@Target({TYPE, METHOD, PARAMETER, FIELD}) | ||
public @interface Default { | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
dirk-annotations/src/main/java/org/int4/dirk/annotations/NormalScope.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.int4.dirk.annotations; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.ANNOTATION_TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
/** | ||
* Specifies that an annotation is a normal scope. | ||
*/ | ||
@Documented | ||
@Retention(RUNTIME) | ||
@Target(ANNOTATION_TYPE) | ||
public @interface NormalScope { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.int4.dirk</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
|
||
<artifactId>dirk-di</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.int4.dirk</groupId> | ||
<artifactId>dirk-annotations</artifactId> | ||
<version>${revision}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.int4.dirk</groupId> | ||
<artifactId>dirk-core</artifactId> | ||
<version>${revision}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.int4.dirk</groupId> | ||
<artifactId>dirk-library</artifactId> | ||
<version>${revision}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.int4.dirk.extensions</groupId> | ||
<artifactId>extensions-assisted</artifactId> | ||
<version>${revision}</version> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.int4.dirk.extensions</groupId> | ||
<artifactId>extensions-proxy</artifactId> | ||
<version>${revision}</version> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>jakarta.inject</groupId> | ||
<artifactId>jakarta.inject-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>jakarta.annotation</groupId> | ||
<artifactId>jakarta.annotation-api</artifactId> | ||
</dependency> | ||
|
||
<!-- Test --> | ||
<dependency> | ||
<groupId>org.int4.dirk</groupId> | ||
<artifactId>dirk-test-util</artifactId> | ||
<version>${revision}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-junit-jupiter</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
32 changes: 32 additions & 0 deletions
32
dirk-di/src/main/java/org/int4/dirk/di/AssistedTypeRegistrationExtensionSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.int4.dirk.di; | ||
|
||
import java.lang.reflect.AnnotatedElement; | ||
|
||
import org.int4.dirk.annotations.Argument; | ||
import org.int4.dirk.annotations.Assisted; | ||
import org.int4.dirk.extensions.assisted.AssistedAnnotationStrategy; | ||
import org.int4.dirk.extensions.assisted.AssistedTypeRegistrationExtension; | ||
import org.int4.dirk.extensions.assisted.ConfigurableAssistedAnnotationStrategy; | ||
import org.int4.dirk.spi.config.AnnotationStrategy; | ||
import org.int4.dirk.spi.config.LifeCycleCallbacksFactory; | ||
import org.int4.dirk.spi.discovery.TypeRegistrationExtension; | ||
import org.int4.dirk.util.Annotations; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.inject.Provider; | ||
|
||
class AssistedTypeRegistrationExtensionSupport { | ||
private static final Inject INJECT = Annotations.of(Inject.class); | ||
|
||
static TypeRegistrationExtension create(AnnotationStrategy annotationStrategy, LifeCycleCallbacksFactory lifeCycleCallbacksFactory) { | ||
AssistedAnnotationStrategy<?> ASSISTED_ANNOTATION_STRATEGY = new ConfigurableAssistedAnnotationStrategy<>(Assisted.class, Argument.class, AssistedTypeRegistrationExtensionSupport::extractArgumentName, INJECT, Provider.class, Provider::get); | ||
|
||
return new AssistedTypeRegistrationExtension(annotationStrategy, lifeCycleCallbacksFactory, ASSISTED_ANNOTATION_STRATEGY); | ||
} | ||
|
||
private static String extractArgumentName(AnnotatedElement element) { | ||
Argument annotation = element.getAnnotation(Argument.class); | ||
|
||
return annotation == null ? null : annotation.value(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
dirk-di/src/main/java/org/int4/dirk/di/ByteBuddyProxyStrategySupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.int4.dirk.di; | ||
|
||
import org.int4.dirk.extensions.proxy.ByteBuddyProxyStrategy; | ||
import org.int4.dirk.spi.config.ProxyStrategy; | ||
|
||
class ByteBuddyProxyStrategySupport { | ||
static ProxyStrategy create() { | ||
return new ByteBuddyProxyStrategy(); | ||
} | ||
} |
Oops, something went wrong.