use of org.nutz.ioc.Ioc in project nutz by nutzam.
the class NutLoading method createIoc.
protected Ioc createIoc(NutConfig config, Class<?> mainModule) throws Exception {
IocBy ib = mainModule.getAnnotation(IocBy.class);
if (null != ib) {
if (log.isDebugEnabled())
log.debugf("@IocBy(type=%s, args=%s,init=%s)", ib.type().getName(), Json.toJson(ib.args()), Json.toJson(ib.init()));
Ioc ioc = Mirror.me(ib.type()).born().create(config, ib.args());
// 如果是 Ioc2 的实现,增加新的 ValueMaker
if (ioc instanceof Ioc2) {
((Ioc2) ioc).addValueProxyMaker(new ServletValueProxyMaker(config.getServletContext()));
}
// 如果给定了 Ioc 的初始化,则依次调用
for (String objName : ib.init()) {
ioc.get(null, objName);
}
// 保存 Ioc 对象
Mvcs.setIoc(ioc);
return ioc;
} else if (log.isInfoEnabled())
log.info("!!!Your application without @IocBy supporting");
return null;
}
use of org.nutz.ioc.Ioc in project nutz by nutzam.
the class MainSetup method init.
public void init(NutConfig nc) {
Ioc ioc = nc.getIoc();
Dao dao = ioc.get(Dao.class);
Daos.createTablesInPackage(dao, getClass(), false);
if (0 == dao.count(User.class)) {
User user = new User();
user.setName("admin");
user.setSalt(R.UU32());
user.setPassword(Lang.digest("SHA-256", user.getSalt() + "123456"));
dao.insert(user);
}
}
use of org.nutz.ioc.Ioc 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.Ioc 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.Ioc 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