Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored the Wire components and renamed to IoC.
- Loading branch information
1 parent
cd99e33
commit ae9e795
Showing
25 changed files
with
216 additions
and
194 deletions.
There are no files selected for viewing
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
36 changes: 36 additions & 0 deletions
36
rapidoid-commons/src/main/java/org/rapidoid/ioc/ClassMetadata.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,36 @@ | ||
package org.rapidoid.ioc; | ||
|
||
import org.rapidoid.annotation.*; | ||
import org.rapidoid.cls.Cls; | ||
import org.rapidoid.commons.Coll; | ||
import org.rapidoid.lambda.F3; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Method; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
@Authors("Nikolche Mihajlovski") | ||
@Since("5.1.0") | ||
public class ClassMetadata { | ||
|
||
final Class<?> clazz; | ||
|
||
final List<Field> injectableFields; | ||
|
||
final List<Field> sessionFields; | ||
|
||
final List<Field> localFields; | ||
|
||
final Set<Object> injectors = Coll.synchronizedSet(); | ||
|
||
final List<F3<Object, Object, Method, Object[]>> interceptors = Coll.synchronizedList(); | ||
|
||
public ClassMetadata(Class<?> clazz) { | ||
this.clazz = clazz; | ||
this.injectableFields = Cls.getFieldsAnnotated(clazz, Inject.class); | ||
this.sessionFields = Cls.getFieldsAnnotated(clazz, Session.class); | ||
this.localFields = Cls.getFieldsAnnotated(clazz, Local.class); | ||
} | ||
|
||
} |
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,58 @@ | ||
package org.rapidoid.ioc; | ||
|
||
/* | ||
* #%L | ||
* rapidoid-commons | ||
* %% | ||
* Copyright (C) 2014 - 2016 Nikolche Mihajlovski and contributors | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
|
||
import org.rapidoid.annotation.Authors; | ||
import org.rapidoid.annotation.Since; | ||
|
||
import java.util.Map; | ||
|
||
@Authors("Nikolche Mihajlovski") | ||
@Since("5.1.0") | ||
public class IoC { | ||
|
||
private static final IoCContext DEFAULT_CONTEXT = new IoCContext(); | ||
|
||
public static synchronized IoCContext getDefault() { | ||
return DEFAULT_CONTEXT; | ||
} | ||
|
||
public static synchronized void manage(Object... classesOrInstances) { | ||
DEFAULT_CONTEXT.manage(classesOrInstances); | ||
} | ||
|
||
public static synchronized <T> T singleton(Class<T> type) { | ||
return DEFAULT_CONTEXT.singleton(type); | ||
} | ||
|
||
public static synchronized <T> T autowire(T target) { | ||
return DEFAULT_CONTEXT.autowire(target); | ||
} | ||
|
||
public static synchronized <T> T inject(T target) { | ||
return DEFAULT_CONTEXT.inject(target); | ||
} | ||
|
||
public static synchronized <T> T inject(T target, Map<String, Object> properties) { | ||
return DEFAULT_CONTEXT.inject(target, properties); | ||
} | ||
|
||
} |
Oops, something went wrong.