Skip to content
This repository has been archived by the owner on Mar 5, 2020. It is now read-only.

Commit

Permalink
added Context/Scope feature to di #54
Browse files Browse the repository at this point in the history
Context/Scope is definded and used by the ServiceProvider
ServiceConsumer have no control over the Scope of referneces
  • Loading branch information
Legion2 committed Jun 14, 2018
1 parent 3b5654e commit e8221a9
Show file tree
Hide file tree
Showing 36 changed files with 891 additions and 414 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@
public interface ServiceLocator {

/**
* Instantiate the given class and inject dependencies. The object created in
* this way will not be managed by the DI.
* Instantiate the given class and inject dependencies. The object created
* in this way will not be managed by the DI.
*
* @param serviceClass
* @return
*/
<T> T create(Class<T> serviceClass);

/**
* Get a Service instance
* Get the service of the given type. This method can return external
* services and does return a object of the type registered for the service
* type.
*
* @param serviceType
* @return
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package de.unistuttgart.iaas.amyassist.amy.core.di.annotation;

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

/**
* Declare the use of context information
*
* @author Leon Kiefer
*/
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Target(java.lang.annotation.ElementType.FIELD)
public @interface Context {
/**
* The class of the context provider to use for getting the context
* information
*
* @return the ContextProvider class
*/
Class<?> value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,5 @@
@Documented
@Target(java.lang.annotation.ElementType.FIELD)
public @interface Reference {
/**
* The {@link Scope scope} of this reference.
*
* @return the scope.
*/
Scope value() default Scope.GLOBAL;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package de.unistuttgart.iaas.amyassist.amy.core.di.context.provider;

/**
* A Static Context Provider which provides context information from then
* consumer class.
*
* @author Leon Kiefer
*/
public interface StaticProvider<T> {
/**
*
* @param consumer
* the class of the consumer
* @return the context information
*/
T getContext(Class<?> consumer);
}
7 changes: 6 additions & 1 deletion di/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<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>
<artifactId>amy-di</artifactId>
Expand Down Expand Up @@ -50,5 +51,9 @@
<version>1.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</dependency>
</dependencies>
</project>
Loading

0 comments on commit e8221a9

Please sign in to comment.