Package org.nutz.ioc

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') but you not declare a Ioc for this app",
                      injectName);
        Object obj;
        /*
         * 如果 Ioc 容器实现了高级接口,那么会为当前请求设置上下文对象
         */
        if (ioc instanceof Ioc2) {
          reqContext = new RequestIocContext(ac.getRequest());
          SessionIocContext sessionContext = new SessionIocContext(ac.getRequest()
                                        .getSession());
          IocContext myContext = new ComboContext(reqContext, sessionContext);
          obj = ((Ioc2) ioc).get(moduleType, injectName, myContext);
        }
        /*
         * 否则,则仅仅简单的从容器获取
         */
        else
          obj = ioc.get(moduleType, injectName);
        ac.setModule(obj);

      }
      ac.setMethod(method);
      doNext(ac);
View Full Code Here


  }

  private static Map<String, Ioc> nuts = new HashMap<String, Ioc>();

  public static Ioc getIoc(String key) {
    Ioc nut = nuts.get(key);
    if (null == nut) {
      synchronized (Nutzs.class) {
        nut = nuts.get(key);
        try {
          if (null == nut) {
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

    s = s + "\nevents:{";
    s = s + "\n  fetch: 'onFetch',";
    s = s + "\n  create: 'onCreate',";
    s = s + "\n  depose: 'onDepose'";
    s = s + "\n}";
    Ioc ioc = I(J("fox", s));

    Animal f = ioc.get(Animal.class, "fox");
    assertEquals(1, f.getCreateTime());
    assertEquals(1, f.getFetchTime());
    assertEquals(0, f.getDeposeTime());

    ioc.get(Animal.class, "fox");

    assertEquals(1, f.getCreateTime());
    assertEquals(2, f.getFetchTime());
    assertEquals(0, f.getDeposeTime());

    ioc.reset();
    assertEquals(1, f.getCreateTime());
    assertEquals(2, f.getFetchTime());
    assertEquals(1, f.getDeposeTime());
  }
View Full Code Here

    s = s + "\nevents:{";
    s = s + "\n  fetch: 'onFetch',";
    s = s + "\n  create: 'onCreate',";
    s = s + "\n  depose: 'onDepose'";
    s = s + "\n}";
    Ioc ioc = I(J("fox", s));

    Animal f = ioc.get(Animal.class, "fox");
    assertEquals(1, f.getCreateTime());
    assertEquals(1, f.getFetchTime());
    assertEquals(0, f.getDeposeTime());

    ioc.get(Animal.class, "fox");

    assertEquals(1, f.getCreateTime());
    assertEquals(1, f.getFetchTime());
    assertEquals(0, f.getDeposeTime());

    ioc.reset();
    assertEquals(1, f.getCreateTime());
    assertEquals(1, f.getFetchTime());
    assertEquals(0, f.getDeposeTime());
  }
View Full Code Here

    s = s + "\nevents:{";
    s = s + "\n  fetch: 'org.nutz.ioc.json.pojo.WhenFetchAnimal',";
    s = s + "\n  create: 'org.nutz.ioc.json.pojo.WhenCreateAnimal',";
    s = s + "\n  depose: 'org.nutz.ioc.json.pojo.WhenDeposeAnimal'";
    s = s + "\n}";
    Ioc ioc = I(J("fox", s));

    Animal f = ioc.get(Animal.class, "fox");
    assertEquals(10, f.getCreateTime());
    assertEquals(10, f.getFetchTime());
    assertEquals(0, f.getDeposeTime());

    ioc.get(Animal.class, "fox");

    assertEquals(10, f.getCreateTime());
    assertEquals(20, f.getFetchTime());
    assertEquals(0, f.getDeposeTime());

    ioc.reset();
    assertEquals(10, f.getCreateTime());
    assertEquals(20, f.getFetchTime());
    assertEquals(10, f.getDeposeTime());
  }
View Full Code Here

    s = s + "\nevents:{";
    s = s + "\n  fetch: 'org.nutz.ioc.json.pojo.WhenFetchAnimal',";
    s = s + "\n  create: 'org.nutz.ioc.json.pojo.WhenCreateAnimal',";
    s = s + "\n  depose: 'org.nutz.ioc.json.pojo.WhenDeposeAnimal'";
    s = s + "\n}";
    Ioc ioc = I(J("fox", s));

    Animal f = ioc.get(Animal.class, "fox");
    assertEquals(10, f.getCreateTime());
    assertEquals(10, f.getFetchTime());
    assertEquals(0, f.getDeposeTime());

    ioc.get(Animal.class, "fox");

    assertEquals(10, f.getCreateTime());
    assertEquals(10, f.getFetchTime());
    assertEquals(0, f.getDeposeTime());

    ioc.reset();
    assertEquals(10, f.getCreateTime());
    assertEquals(10, f.getFetchTime());
    assertEquals(0, f.getDeposeTime());
  }
View Full Code Here

    assertEquals(0, f.getDeposeTime());
  }

  @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());
  }
View Full Code Here

    s += "b:{type:'org.nutz.ioc.json.RecurReferJsonIocTest$RB',";
    s += "fields:{nm:'B', ra:{refer:'a'}}";
    s += "}";
    s += "}";

    Ioc ioc = new NutIoc(new MapLoader(s));
    RA a = ioc.get(RA.class, "a");
    assertEquals("A", a.nm);
    assertEquals("B", a.rb.nm);

    RB b = ioc.get(RB.class, "b");
    assertEquals("A", b.ra.nm);
    assertEquals("B", b.nm);
  }
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.