Search in sources :

Example 6 with BeanDefine

use of com.blade.ioc.bean.BeanDefine in project blade by biezhi.

the class SimpleIoc method setBean.

/**
 * Update BeanDefine
 */
@Override
public void setBean(Class<?> type, Object proxyBean) {
    BeanDefine beanDefine = pool.get(type.getName());
    if (beanDefine != null) {
        beanDefine.setBean(proxyBean);
    } else {
        beanDefine = new BeanDefine(proxyBean, type);
    }
    pool.put(type.getName(), beanDefine);
}
Also used : BeanDefine(com.blade.ioc.bean.BeanDefine)

Example 7 with BeanDefine

use of com.blade.ioc.bean.BeanDefine in project blade by biezhi.

the class SimpleIoc method addBean.

/**
 * Add user-defined objects
 */
@Override
public void addBean(String name, Object bean) {
    BeanDefine beanDefine = new BeanDefine(bean);
    put(name, beanDefine);
    // add interface态put to pool
    Class<?>[] interfaces = beanDefine.getType().getInterfaces();
    if (interfaces.length > 0) {
        for (Class<?> interfaceClazz : interfaces) {
            this.put(interfaceClazz.getName(), beanDefine);
        }
    }
}
Also used : BeanDefine(com.blade.ioc.bean.BeanDefine)

Example 8 with BeanDefine

use of com.blade.ioc.bean.BeanDefine in project blade by biezhi.

the class BeanDefineTest method testBeanDefine.

@Test
public void testBeanDefine() {
    BeanDefine beanDefine = new BeanDefine(new BladeBeanDefineType());
    Class<?> type = beanDefine.getType();
    assertEquals(BladeBeanDefineType.class, type);
    Object bean = beanDefine.getBean();
    assertNotNull(bean);
    assertEquals(true, beanDefine.isSingleton());
    beanDefine.setSingleton(true);
    beanDefine.setType(BladeBeanDefineType.class);
    beanDefine.setBean(new BladeBeanDefineType());
    assertEquals(BladeBeanDefineType.class, type);
    assertNotNull(bean);
    assertEquals(true, beanDefine.isSingleton());
}
Also used : BladeBeanDefineType(com.blade.types.BladeBeanDefineType) BeanDefine(com.blade.ioc.bean.BeanDefine) Test(org.junit.Test)

Aggregations

BeanDefine (com.blade.ioc.bean.BeanDefine)8 BladeBeanDefineType (com.blade.types.BladeBeanDefineType)2 Test (org.junit.Test)2 Ioc (com.blade.ioc.Ioc)1 ClassDefine (com.blade.ioc.bean.ClassDefine)1 ClassInfo (com.blade.ioc.bean.ClassInfo)1 FieldInjector (com.blade.ioc.bean.FieldInjector)1 OrderComparator (com.blade.ioc.bean.OrderComparator)1 RouteBuilder (com.blade.mvc.route.RouteBuilder)1 RouteMatcher (com.blade.mvc.route.RouteMatcher)1 TaskStruct (com.blade.task.TaskStruct)1