Package org.nutz.ioc

Examples of org.nutz.ioc.Ioc


    assertEquals(10, f3.getAge());
  }

  @Test
  public void test_create_by_args() {
    Ioc ioc = I(J("fox", "age:10"), J("xb", "parent:'fox',args:['XiaoBai']"));
    Animal xb = ioc.get(Animal.class, "xb");
    assertEquals("XiaoBai", xb.getName());
  }
View Full Code Here


    assertEquals("XiaoBai", xb.getName());
  }

  @Test(expected = IocException.class)
  public void test_break_parent() {
    Ioc ioc = I(J("f2", "parent:'f3'"), J("f3", "parent:'f2'"));
    ioc.get(Animal.class, "f3");
  }
View Full Code Here

    ioc.get(Animal.class, "f3");
  }

  @Test(expected = IocException.class)
  public void test_break_parent2() {
    Ioc ioc = I(J("fox", "name:'P',age:10"), J("f2", "parent:'x'"), J("f3", "parent:'y'"));
    ioc.get(Animal.class, "f3");
  }
View Full Code Here

    assertTrue(loader.getName().length > 0);
  }

  @Test
  public void test_get_ioc_self() {
    Ioc ioc = I(J("iocV", "type:'org.nutz.ioc.json.pojo.IocSelf',fields:{ioc:{refer : '$iOc'}}"));
    assertEquals(ioc, ioc.get(IocSelf.class, "iocV").getIoc());
  }
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

    }
  }

  @Test
  public void test_simple_case() {
    Ioc ioc = new NutIoc(getNew("org/nutz/ioc/loader/xml/conf/simple.xml"));
    Bee c = ioc.get(Bee.class, "C");
    assertEquals("TheC", c.getName());
    assertEquals(15, c.getAge());
    assertEquals("TheQueen", c.getMother().getName());
    assertEquals(3, c.getFriends().size());
    assertEquals("TheA", c.getFriends().get(0).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

    }
    catch (Exception e) {
      throw new LoadingException(e);
    }
    // If the application has Ioc, depose it
    Ioc ioc = config.getIoc();
    if (null != ioc)
      ioc.depose();

    // Done, print info
    sw.stop();
    if (log.isInfoEnabled())
      log.infof("Nutz.Mvc[%s] is down in %sms", config.getAppName(), sw.getDuration());
View Full Code Here

    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

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

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.