Skip to content
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

[#2138]enhance the function for the injector (Add the injectable interface) #1186

Merged
merged 3 commits into from
Oct 13, 2017
Merged
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
3 changes: 2 additions & 1 deletion framework/src/play/inject/Injector.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class Injector {

/**
* For now, inject beans in controllers
* For now, inject beans in controllers and any classes that include @RequireInjection.
*
* @param source
* the beanSource to inject
Expand All @@ -24,6 +24,7 @@ public static void inject(BeanSource source) {
List<Class> classes = new ArrayList<>(Play.classloader.getAssignableClasses(ControllerSupport.class));
classes.addAll(Play.classloader.getAssignableClasses(Mailer.class));
classes.addAll(Play.classloader.getAssignableClasses(Job.class));
classes.addAll(Play.classloader.getAnnotatedClasses(RequireInjection.class));
for (Class<?> clazz : classes) {
for (Field field : clazz.getDeclaredFields()) {
if (Modifier.isStatic(field.getModifiers()) && field.isAnnotationPresent(Inject.class)) {
Expand Down
13 changes: 13 additions & 0 deletions framework/src/play/inject/RequireInjection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package play.inject;

import java.lang.annotation.*;

/**
* if you want to inject beans anywhere,please implement the interface.
*
*/
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface RequireInjection {
}