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);
}
}
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();
}
}
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();
}
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);
}
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());
}
Aggregations