Skip to content

Commit

Permalink
Merge pull request #12 from unnamed/refactor/remove-javax.inject
Browse files Browse the repository at this point in the history
BREAKING! Remove `javax.inject`
  • Loading branch information
yusshu authored Apr 5, 2023
2 parents 56bfcb8 + 89f9f93 commit 385cd31
Show file tree
Hide file tree
Showing 64 changed files with 121 additions and 95 deletions.
2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ repositories {
}

dependencies {
api("javax.inject:javax.inject:1")

testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.2")
}
Expand Down
2 changes: 1 addition & 1 deletion docs/config/bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ provider is called
### Direct Binding

A direct binding is a binding of a type to a provider function
(`javax.inject.Provider<T>`)
(`team.unnamed.inject.Provider<T>`)

```java
binder.bind(Database.class).toProvider(() -> {
Expand Down
2 changes: 1 addition & 1 deletion docs/dependency-injection.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ and re-usable
Here is an example that uses dependency injection with `unnamed/inject`

```java
import javax.inject.Inject;
import team.unnamed.inject.Inject;

public class UserDao {

Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Welcome to the `inject` documentation

`unnamed/inject` is a zero-dependency, lightweight and fast runtime dependency
injection library compatible with the JSR-330 specification for Java 8+
injection library for Java 8+


### Features
Expand Down
4 changes: 2 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Add the dependency

```kotlin
dependencies {
implementation("team.unnamed:inject:1.0.2")
implementation("team.unnamed:inject:2.0.0")
}
```

Expand All @@ -39,6 +39,6 @@ Add the dependency
<dependency>
<groupId>team.unnamed</groupId>
<artifactId>inject</artifactId>
<version>1.0.2</version>
<version>2.0.0</version>
</dependency>
```
3 changes: 1 addition & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
[![Discord](https://img.shields.io/discord/683899335405994062)](https://discord.gg/xbba2fy)

`unnamed/inject` is a zero-dependency, lightweight and fast runtime dependency
injection library based on [Google's Guice](https://github.com/google/guice),
compatible with the JSR-330 specification for Java 8+
injection library based on [Google's Guice](https://github.com/google/guice) for Java 8+

By not having to worry about manually injecting dependencies, this library
will potentially increase your programming productivity
Expand Down
1 change: 0 additions & 1 deletion src/main/java/team/unnamed/inject/Binder.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import team.unnamed.inject.scope.Scope;
import team.unnamed.inject.scope.Scopes;

import javax.inject.Provider;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/team/unnamed/inject/Delegated.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package team.unnamed.inject;

import javax.inject.Qualifier;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/team/unnamed/inject/Inject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package team.unnamed.inject;


import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.FIELD;

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({METHOD, CONSTRUCTOR, FIELD})
public @interface Inject {
}
1 change: 0 additions & 1 deletion src/main/java/team/unnamed/inject/Injector.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import team.unnamed.inject.impl.InjectorImpl;
import team.unnamed.inject.key.TypeReference;

import javax.inject.Provider;
import java.util.Arrays;

public interface Injector {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/team/unnamed/inject/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
* configuration. A module is usually used to bind abstractions
* (interfaces, abstract classes) to implementations (concrete
* classes). To just add a scope to a class, you can use scope
* annotations like {@link javax.inject.Singleton}.
* annotations like {@link Singleton}.
* You can also use annotations to bind abstractions to implementations
* like {@link Targetted} and {@link ProvidedBy}.
*
* <p>Read about the embedded dsl to configure injector in {@link Binder}.</p>
*
* <p>You can also create provider methods (methods used as providers) and
* annotate it with {@link Provides}. Annotate the method with
* {@link javax.inject.Inject} if the object creation has dependencies.</p>
* {@link Inject} if the object creation has dependencies.</p>
*
* <p>There's an extension for users to create bindings in a pretty way
* using {@link AbstractModule}.</p>
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/team/unnamed/inject/Named.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package team.unnamed.inject;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Qualifier
@Documented
@Retention(RetentionPolicy.RUNTIME)
public @interface Named {

String value() default "";

}
1 change: 0 additions & 1 deletion src/main/java/team/unnamed/inject/ProvidedBy.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package team.unnamed.inject;

import javax.inject.Provider;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/team/unnamed/inject/Provider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package team.unnamed.inject;

public interface Provider<T> {

T get();

}
13 changes: 13 additions & 0 deletions src/main/java/team/unnamed/inject/Qualifier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package team.unnamed.inject;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.ANNOTATION_TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Qualifier {
}
13 changes: 13 additions & 0 deletions src/main/java/team/unnamed/inject/Scope.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package team.unnamed.inject;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.ANNOTATION_TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Scope {
}
11 changes: 11 additions & 0 deletions src/main/java/team/unnamed/inject/Singleton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package team.unnamed.inject;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Scope
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Singleton {
}
4 changes: 2 additions & 2 deletions src/main/java/team/unnamed/inject/impl/AnnotationScanner.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package team.unnamed.inject.impl;

import team.unnamed.inject.ProvidedBy;
import team.unnamed.inject.Provider;
import team.unnamed.inject.Singleton;
import team.unnamed.inject.Targetted;
import team.unnamed.inject.key.Key;
import team.unnamed.inject.key.TypeReference;
Expand All @@ -9,8 +11,6 @@
import team.unnamed.inject.scope.Scope;
import team.unnamed.inject.scope.Scopes;

import javax.inject.Provider;
import javax.inject.Singleton;
import java.lang.reflect.Modifier;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/team/unnamed/inject/impl/Annotations.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package team.unnamed.inject.impl;

import team.unnamed.inject.Named;
import team.unnamed.inject.util.Validate;

import javax.inject.Named;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/team/unnamed/inject/impl/BinderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import team.unnamed.inject.Binder;
import team.unnamed.inject.Module;
import team.unnamed.inject.Provider;
import team.unnamed.inject.error.BindingException;
import team.unnamed.inject.error.ErrorAttachableImpl;
import team.unnamed.inject.key.Key;
Expand All @@ -13,7 +14,6 @@
import team.unnamed.inject.provision.std.generic.impl.TypeReferenceGenericProvider;
import team.unnamed.inject.util.Validate;

import javax.inject.Provider;
import java.util.HashMap;
import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package team.unnamed.inject.impl;

import team.unnamed.inject.Binder;
import team.unnamed.inject.Provider;
import team.unnamed.inject.key.Key;
import team.unnamed.inject.key.TypeReference;
import team.unnamed.inject.provision.Providers;
import team.unnamed.inject.scope.Scope;
import team.unnamed.inject.util.Validate;

import javax.inject.Provider;

class BindingBuilderImpl<T> implements
Binder.QualifiedBindingBuilder<T>,
KeyBuilder<Binder.QualifiedBindingBuilder<T>, T>,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/team/unnamed/inject/impl/InjectorImpl.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package team.unnamed.inject.impl;

import team.unnamed.inject.Injector;
import team.unnamed.inject.Provider;
import team.unnamed.inject.error.InjectionException;
import team.unnamed.inject.key.InjectedKey;
import team.unnamed.inject.key.Key;
Expand All @@ -11,7 +12,6 @@
import team.unnamed.inject.resolve.solution.InjectableMember;
import team.unnamed.inject.util.Validate;

import javax.inject.Provider;
import java.util.List;

public class InjectorImpl implements Injector {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/team/unnamed/inject/impl/LinkedBuilder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package team.unnamed.inject.impl;

import team.unnamed.inject.Binder;
import team.unnamed.inject.Provider;
import team.unnamed.inject.assisted.ValueFactory;
import team.unnamed.inject.assisted.provision.ToFactoryProvider;
import team.unnamed.inject.key.Key;
Expand All @@ -10,8 +11,6 @@
import team.unnamed.inject.provision.std.generic.ToGenericProvider;
import team.unnamed.inject.util.Validate;

import javax.inject.Provider;

public interface LinkedBuilder<R, T> extends Binder.Linked<R, T> {

Key<T> key();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/team/unnamed/inject/key/Key.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package team.unnamed.inject.key;

import team.unnamed.inject.Qualifier;
import team.unnamed.inject.key.Types.CompositeType;
import team.unnamed.inject.util.ElementFormatter;
import team.unnamed.inject.util.Validate;

import javax.inject.Qualifier;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.util.Objects;
Expand Down Expand Up @@ -169,7 +169,7 @@ public int hashCode() {
* marked with @Marker
* </pre>
*
* If a class name starts with {@code java} or {@code javax},
* If a class name starts with {@code java},
* it isn't used, the used name is now {@link Class#getSimpleName()}
*
* @return The key information as string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package team.unnamed.inject.multibinding;

import team.unnamed.inject.Provider;
import team.unnamed.inject.impl.InjectorImpl;
import team.unnamed.inject.impl.ProvisionStack;
import team.unnamed.inject.key.Key;
import team.unnamed.inject.key.TypeReference;
import team.unnamed.inject.provision.StdProvider;

import javax.inject.Provider;
import java.util.Collection;
import java.util.Collections;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package team.unnamed.inject.multibinding;

import team.unnamed.inject.Binder;
import team.unnamed.inject.Provider;
import team.unnamed.inject.impl.BinderImpl;
import team.unnamed.inject.impl.LinkedBuilder;
import team.unnamed.inject.key.Key;
Expand All @@ -9,7 +10,6 @@
import team.unnamed.inject.scope.Scope;
import team.unnamed.inject.util.Validate;

import javax.inject.Provider;
import java.util.Collection;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package team.unnamed.inject.multibinding;

import team.unnamed.inject.Provider;
import team.unnamed.inject.impl.InjectorImpl;
import team.unnamed.inject.impl.ProvisionStack;
import team.unnamed.inject.provision.Providers;
import team.unnamed.inject.provision.StdProvider;

import javax.inject.Provider;
import java.util.Collections;
import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package team.unnamed.inject.multibinding;

import team.unnamed.inject.Binder;
import team.unnamed.inject.Provider;
import team.unnamed.inject.impl.BinderImpl;
import team.unnamed.inject.impl.LinkedBuilder;
import team.unnamed.inject.key.Key;
Expand All @@ -9,7 +10,6 @@
import team.unnamed.inject.scope.Scope;
import team.unnamed.inject.util.Validate;

import javax.inject.Provider;
import java.util.Map;

class MapMultiBindingBuilderImpl<K, V> implements Binder.MapMultiBindingBuilder<K, V> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package team.unnamed.inject.provision;

import team.unnamed.inject.Provider;
import team.unnamed.inject.impl.BinderImpl;
import team.unnamed.inject.impl.InjectorImpl;
import team.unnamed.inject.impl.ProvisionStack;
import team.unnamed.inject.key.Key;
import team.unnamed.inject.scope.Scope;
import team.unnamed.inject.util.Validate;

import javax.inject.Provider;
import java.util.Objects;

/**
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/team/unnamed/inject/provision/Providers.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package team.unnamed.inject.provision;

import team.unnamed.inject.Provider;
import team.unnamed.inject.impl.InjectorImpl;
import team.unnamed.inject.impl.ProvisionStack;
import team.unnamed.inject.key.Key;
Expand All @@ -10,8 +11,6 @@
import team.unnamed.inject.provision.std.ScopedProvider;
import team.unnamed.inject.util.Validate;

import javax.inject.Provider;

/**
* Collection of static factory methods to create providers
*/
Expand Down
Loading

0 comments on commit 385cd31

Please sign in to comment.