Examples of Ioc


Examples of org.nutz.ioc.Ioc

    this.objType = objType;
    this.objName = objName;
  }

  public Object get(ServletContext sc, HttpServletRequest req, HttpServletResponse resp, Object refer) {
    Ioc ioc = Mvcs.getIoc(sc);
    if (null == ioc)
      throw new RuntimeException("You need define @IocBy in main module!!!");
    if (Strings.isBlank(objName))
      return ioc.get(objType);
    return ioc.get(objType, objName);
  }
View Full Code Here

Examples of org.nutz.ioc.Ioc

public class JsonAopConfigrationTest {

  @Test
  public void test_jsonAop(){
    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);
  }
View Full Code Here

Examples of org.nutz.ioc.Ioc

public class AopJsonIocTest {

    @Test
    public void test_simple() {
        IocLoader il = new JsonLoader("org/nutz/ioc/json/aop.js");
        Ioc ioc = new NutIoc(il);
        StringBuilder sb = ioc.get(StringBuilder.class, "sb");
        Mammal fox = ioc.get(Mammal.class, "fox");

        assertEquals("Fox", fox.getName());
        assertEquals("B:getName0;A:getName0;", sb.toString());
        sb.delete(0, sb.length());
        fox.getName();
View Full Code Here

Examples of org.nutz.ioc.Ioc

        RequestIocContext reqContext = null;
        try {
            if (null != moduleObj) {
                ac.setModule(moduleObj);
            } else {
                Ioc ioc = ac.getIoc();
                if (null == ioc)
                    throw Lang.makeThrow(    "Moudle with @InjectName('%s') or @IocBean('%s') but you not declare a Ioc for this app",
                                            injectName, injectName);
                Object obj;
                /*
                 * 如果 Ioc 容器实现了高级接口,那么会为当前请求设置上下文对象
                 */
                if (ioc instanceof Ioc2) {
                    reqContext = new RequestIocContext(ac.getRequest());
                    SessionIocContext sessionContext = new SessionIocContext(Mvcs.getHttpSession());
                    IocContext myContext = new ComboContext(reqContext, sessionContext);
                    Mvcs.setIocContext(myContext);
                    obj = ((Ioc2) ioc).get(moduleType, injectName, myContext);
                }
                /*
                 * 否则,则仅仅简单的从容器获取
                 */
                else
                    obj = ioc.get(moduleType, injectName);
                ac.setModule(obj);

            }
            ac.setMethod(method);
            //if (log.isDebugEnabled()) //打印实际执行的Method信息
View Full Code Here

Examples of org.nutz.ioc.Ioc

public class PojoTest {

  public static void main(String[] args) {
    IocLoader loader = new JsonLoader("ioc.js");
    Ioc ioc = new NutIoc(loader);
    Pet pet = ioc.get(Pet.class, "pet");
    System.out.println(pet.getName());
  }
View Full Code Here

Examples of org.nutz.ioc.Ioc

        IocBy ib = mainModule.getAnnotation(IocBy.class);
        if (null != ib) {
            if (log.isDebugEnabled())
                log.debugf("@IocBy(%s)", ib.type().getName());

            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 对象
View Full Code Here

Examples of org.nutz.ioc.Ioc

        finally {
            SessionProvider sp = config.getSessionProvider();
            if (sp != null)
                sp.notifyStop();
            // If the application has Ioc, depose it
            Ioc ioc = config.getIoc();
            if (null != ioc)
                ioc.depose();
        }

        // Done, print info
        sw.stop();
        if (log.isInfoEnabled())
View Full Code Here

Examples of org.nutz.ioc.Ioc

    }
  }

  @SuppressWarnings("unchecked")
  public Object getInstance() throws InstantiationException {
    Ioc ioc = this.ioc;
    if (ioc == null)
      ioc = Mvcs.getIoc();
    if (beanName != null)
      return ioc.get(clazz, beanName);
    return ioc.get(clazz);
  }
View Full Code Here

Examples of org.nutz.ioc.Ioc

 
  private String name;
 
  public Dao dao() {
    if (dao == null) {
      Ioc ioc = Webs.ioc();
      dao = ioc.get(Dao.class, daoBeanName);
      return dao;
    }
    return dao;
  }
View Full Code Here

Examples of org.nutz.ioc.Ioc

        this.name = p.getName();
        this.type = p.getValue();
    }

    public Object get(IocMaking ing) {
        Ioc ioc = ing.getIoc();
        if (ioc instanceof Ioc2)
            return ((Ioc2)ioc).get(type, name,ing.getContext());
        return ioc.get(type, name);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.