use of com.blade.ioc.bean.FieldInjector 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.FieldInjector in project blade by biezhi.
the class FieldInjectorTest method testFieldInjector.
@Test
public void testFieldInjector() {
Ioc ioc = new SimpleIoc();
ioc.addBean("jack");
ioc.addBean(new BladeBeanDefineType());
Field field = BladeBeanDefineType.class.getDeclaredFields()[0];
FieldInjector fieldInjector = new FieldInjector(ioc, field);
fieldInjector.injection(ioc.getBean(BladeBeanDefineType.class));
}
use of com.blade.ioc.bean.FieldInjector 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);
});
}
use of com.blade.ioc.bean.FieldInjector in project blade by biezhi.
the class FieldInjectorTest method testFieldInjectorError.
@Test(expected = RuntimeException.class)
public void testFieldInjectorError() {
Ioc ioc = new SimpleIoc();
FieldInjector fieldInjector = new FieldInjector(ioc, null);
fieldInjector.injection(new BladeBeanDefineType());
}
Aggregations