Skip to content

Commit

Permalink
Add dirk-di module with Dirk flavored injector configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
hjohn committed May 29, 2022
1 parent 72b3b78 commit c2a93a4
Show file tree
Hide file tree
Showing 10 changed files with 1,176 additions and 0 deletions.
26 changes: 26 additions & 0 deletions dirk-annotations/src/main/java/org/int4/dirk/annotations/Any.java
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 {

}
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 {

}
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 {

}
73 changes: 73 additions & 0 deletions dirk-di/pom.xml
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>
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();
}
}
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();
}
}
Loading

0 comments on commit c2a93a4

Please sign in to comment.