use of com.blade.ioc.bean.ClassDefine in project blade by biezhi.
the class IocKit method initInjection.
public static void initInjection(Ioc ioc, BeanDefine beanDefine) {
ClassDefine classDefine = ClassDefine.create(beanDefine.getType());
List<FieldInjector> fieldInjectors = getInjectFields(ioc, classDefine);
Object bean = beanDefine.getBean();
AtomicBoolean hasPrototypeField = new AtomicBoolean(false);
fieldInjectors.forEach(fieldInjector -> {
if (fieldInjector.isSingleton()) {
fieldInjector.injection(bean);
} else {
hasPrototypeField.set(true);
}
});
beanDefine.setFieldHasPrototype(hasPrototypeField.get());
}
use of com.blade.ioc.bean.ClassDefine in project blade by biezhi.
the class IocKit method injectionValue.
public static void injectionValue(Environment environment, BeanDefine beanDefine) {
ClassDefine classDefine = ClassDefine.create(beanDefine.getType());
List<ValueInjector> valueFields = getValueInjectFields(environment, classDefine);
Object bean = beanDefine.getBean();
valueFields.forEach(fieldInjector -> fieldInjector.injection(bean));
}
use of com.blade.ioc.bean.ClassDefine in project blade by biezhi.
the class ClassDefineTest method testClassDefine.
@Test
public void testClassDefine() {
ClassDefine classDefine = ClassDefine.create(BladeClassDefineType.class);
int modifires = classDefine.getModifiers();
Field[] fields = classDefine.getDeclaredFields();
Bean bean = classDefine.getAnnotation(Bean.class);
Annotation[] annotations = classDefine.getAnnotations();
List<ClassDefine> interfaces = classDefine.getInterfaces();
String name = classDefine.getName();
String simpleName = classDefine.getSimpleName();
ClassDefine superKlass = classDefine.getSuperKlass();
Class<?> type = classDefine.getType();
assertEquals(Modifier.PUBLIC, modifires);
assertEquals(2, fields.length);
assertNotNull(bean);
assertEquals(1, annotations.length);
assertEquals(0, interfaces.size());
assertEquals("com.blade.types.BladeClassDefineType", name);
assertEquals("BladeClassDefineType", simpleName);
assertEquals(Object.class, superKlass.getType());
assertEquals(BladeClassDefineType.class, type);
assertEquals(false, classDefine.isAbstract());
assertEquals(false, classDefine.isInterface());
assertEquals(false, classDefine.isStatic());
assertEquals(true, classDefine.isPublic());
assertEquals(false, classDefine.isPrivate());
assertEquals(false, classDefine.isProtected());
assertEquals(1, ClassDefine.create(BladeWebHookType.class).getInterfaces().size());
assertEquals(1, ClassDefine.create(BladeWebHookType.class).getInterfaces().size());
}
use of com.blade.ioc.bean.ClassDefine in project blade by biezhi.
the class IocKit method injection.
public static void injection(Ioc ioc, BeanDefine beanDefine) {
ClassDefine classDefine = ClassDefine.create(beanDefine.getType());
List<FieldInjector> fieldInjectors = getInjectFields(ioc, classDefine);
Object bean = beanDefine.getBean();
fieldInjectors.forEach(fieldInjector -> {
Object fieldInstance = ReflectKit.newInstance(fieldInjector.getType());
if (fieldInjector.hasInjectFields()) {
injection(ioc, new BeanDefine(fieldInstance));
}
fieldInjector.injection(bean, fieldInstance);
});
}
Aggregations