Search in sources :

Example 21 with Ioc

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;
}
Also used : Ioc2(org.nutz.ioc.Ioc2) IocBy(org.nutz.mvc.annotation.IocBy) Ioc(org.nutz.ioc.Ioc)

Example 22 with Ioc

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);
    }
}
Also used : Dao(org.nutz.dao.Dao) User(net.wendal.nutzdemo.bean.User) Ioc(org.nutz.ioc.Ioc)

Example 23 with Ioc

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();
}
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 24 with Ioc

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);
}
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 25 with Ioc

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

Ioc (org.nutz.ioc.Ioc)35 NutIoc (org.nutz.ioc.impl.NutIoc)29 Test (org.junit.Test)27 Animal (org.nutz.ioc.json.pojo.Animal)15 JsonLoader (org.nutz.ioc.loader.json.JsonLoader)6 Ioc2 (org.nutz.ioc.Ioc2)3 IocContext (org.nutz.ioc.IocContext)2 IocLoader (org.nutz.ioc.IocLoader)2 IocTO00 (org.nutz.ioc.json.pojo.IocTO00)2 MapLoader (org.nutz.ioc.loader.map.MapLoader)2 Stopwatch (org.nutz.lang.Stopwatch)2 LoadingException (org.nutz.mvc.LoadingException)2 File (java.io.File)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 HttpSession (javax.servlet.http.HttpSession)1 User (net.wendal.nutzdemo.bean.User)1 Dao (org.nutz.dao.Dao)1 ComboContext (org.nutz.ioc.impl.ComboContext)1