Search in sources :

Example 11 with NutIoc

use of org.nutz.ioc.impl.NutIoc in project nutz by nutzam.

the class NutMvcListener method initIoc.

/**
     * 初始化Ioc容器,使用ComboIocLoader作为配置方式
     */
protected void initIoc() {
    String key = "nutz-" + IOCBY;
    String iocby = pp.get(key);
    if (Strings.isBlank(iocby)) {
        throw new RuntimeException(key + " not found nutz.ini or context-param !!");
    }
    String[] args = Strings.splitIgnoreBlank(iocby);
    for (int i = 0; i < args.length; i++) {
        args[i] = args[i].trim();
    }
    log.info("init Ioc by args=" + Arrays.toString(args));
    try {
        ioc = new NutIoc(new ComboIocLoader(args));
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) ComboIocLoader(org.nutz.ioc.loader.combo.ComboIocLoader)

Example 12 with NutIoc

use of org.nutz.ioc.impl.NutIoc in project nutz by nutzam.

the class SimpleIocTest method test_issue_1232.

@Test(expected = IocException.class)
public void test_issue_1232() {
    Ioc ioc = null;
    try {
        ioc = new NutIoc(new AnnotationIocLoader("org.nutz.ioc.meta.issue1232"));
        assertEquals(3, ioc.getNames().length);
        ioc.get(null, "a");
    } catch (IocException e) {
        e.printStackTrace();
        throw e;
    } finally {
        if (ioc != null)
            ioc.depose();
    }
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) AnnotationIocLoader(org.nutz.ioc.loader.annotation.AnnotationIocLoader) NutIoc(org.nutz.ioc.impl.NutIoc) Test(org.junit.Test)

Example 13 with NutIoc

use of org.nutz.ioc.impl.NutIoc in project nutz by nutzam.

the class JsonAopConfigrationTest method test_jsonAop.

@Test
public void test_jsonAop() {
    Nutzs.cd();
    Ioc ioc = new NutIoc(new JsonLoader("org/nutz/ioc/aop/config/impl/jsonfile-aop.js"));
    Assert.assertTrue(ioc.getNames().length > 0);
    for (String name : ioc.getNames()) {
        ioc.get(null, name);
    }
    MyMI mi = ioc.get(MyMI.class, "myMI");
    assertTrue(mi.getTime() == 0);
    Pet2 pet2 = ioc.get(Pet2.class, "pet2");
    pet2.sing();
    assertTrue(mi.getTime() == 1);
    pet2.sing();
    assertTrue(mi.getTime() == 2);
    ioc.depose();
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) JsonLoader(org.nutz.ioc.loader.json.JsonLoader) Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc) Test(org.junit.Test)

Example 14 with NutIoc

use of org.nutz.ioc.impl.NutIoc in project nutz by nutzam.

the class SimpleAopConfigureTest method aop_maker_inject.

@Test
public void aop_maker_inject() {
    OneObject.COUNT = 0;
    Ioc ioc = new NutIoc(new AnnotationIocLoader(getClass().getPackage().getName()));
    ioc.get(BeAop.class);
    ioc.get(AbcSimpleAop.class);
    ioc.get(OneObject.class);
    ioc.depose();
    assertEquals(1, OneObject.COUNT);
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) AnnotationIocLoader(org.nutz.ioc.loader.annotation.AnnotationIocLoader) Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc) Test(org.junit.Test)

Example 15 with NutIoc

use of org.nutz.ioc.impl.NutIoc in project nutz by nutzam.

the class EvensJsonIocTest method test_event_from_parent.

@Test
public void test_event_from_parent() {
    Ioc ioc = new NutIoc(new JsonLoader("org/nutz/ioc/json/events.js"));
    Animal f = ioc.get(Animal.class, "fox");
    assertEquals(1, f.getCreateTime());
    assertEquals(1, f.getFetchTime());
    assertEquals(0, f.getDeposeTime());
    ioc.depose();
    assertEquals(1, f.getCreateTime());
    assertEquals(1, f.getFetchTime());
    assertEquals(1, f.getDeposeTime());
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) Animal(org.nutz.ioc.json.pojo.Animal) JsonLoader(org.nutz.ioc.loader.json.JsonLoader) Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc) Test(org.junit.Test)

Aggregations

NutIoc (org.nutz.ioc.impl.NutIoc)20 Test (org.junit.Test)16 Ioc (org.nutz.ioc.Ioc)10 JsonLoader (org.nutz.ioc.loader.json.JsonLoader)6 MapLoader (org.nutz.ioc.loader.map.MapLoader)6 AnnotationIocLoader (org.nutz.ioc.loader.annotation.AnnotationIocLoader)4 Ioc2 (org.nutz.ioc.Ioc2)3 IocContext (org.nutz.ioc.IocContext)2 IocLoader (org.nutz.ioc.IocLoader)2 ScopeContext (org.nutz.ioc.impl.ScopeContext)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Before (org.junit.Before)1 NutDao (org.nutz.dao.impl.NutDao)1 Pet (org.nutz.dao.test.meta.Pet)1 IocMaking (org.nutz.ioc.IocMaking)1 ObjectProxy (org.nutz.ioc.ObjectProxy)1 ValueProxy (org.nutz.ioc.ValueProxy)1 ValueProxyMaker (org.nutz.ioc.ValueProxyMaker)1 ComboContext (org.nutz.ioc.impl.ComboContext)1