Package org.nutz.ioc

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


        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

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

        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

        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

    }
  }

  @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

 
  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

        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

    static String J(String name, String s) {
        return name + " : {" + s + "}";
    }

    static Animal A(String s) {
        Ioc ioc = I(J("obj", s));
        return ioc.get(Animal.class, "obj");
    }
View Full Code Here

    public void test_init_with_field() {
        String s = "fields: {name:'Fox'},";
        s = s + "\nevents:{";
        s = s + "\n    create: 'org.nutz.ioc.json.pojo.WhenCreateFox'";
        s = s + "\n}";
        Ioc ioc = I(J("fox", s));

        Animal fox = ioc.get(Animal.class, "fox");
        assertEquals("$Fox", fox.getName());
    }
View Full Code Here

TOP

Related Classes of org.nutz.ioc.Ioc

Copyright © 2018 www.massapicom. 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.