Package org.nutz.ioc.impl

Examples of org.nutz.ioc.impl.NutIoc


    if (null == nut) {
      synchronized (Nutzs.class) {
        nut = nuts.get(key);
        try {
          if (null == nut) {
            nut = new NutIoc(new JsonLoader(key));
            nuts.put(key, nut);
          }
        }
        catch (Exception e) {
          throw Lang.wrapThrow(e);
View Full Code Here


  static Ioc2 I(String... ss) {
    String json = "{";
    json += Lang.concat(',', ss);
    json += "}";
    return new NutIoc(new MapLoader(json));
  }
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

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

public class IocCustomizedValueTypeTest {

  @Test
  public void test_simple_customized() {
    String json = "{xb:{name:{cc:'XiaoBai'}}}";
    Ioc2 ioc = new NutIoc(new MapLoader(json));
    ioc.addValueProxyMaker(new ValueProxyMaker() {
      public ValueProxy make(IocMaking ing, IocValue iv) {
        if ("cc".equalsIgnoreCase(iv.getType())) {
          return new StaticValue("CC:" + iv.getValue());
        }
        return null;
      }

      public String[] supportedTypes() {
        return Lang.array("cc");
      }
    });

    Pet pet = ioc.get(Pet.class, "xb");
    assertEquals("CC:XiaoBai", pet.getName());
  }
View Full Code Here

  }

  @Test
  public void test_null_json_file() {
    IocLoader loader = new JsonLoader("org/nutz/ioc/json/empty.js");
    Ioc ioc = new NutIoc(loader);
    assertEquals(0, ioc.getNames().length);
  }
View Full Code Here

  @Test
  public void test_refer_context() {
    IocContext context = new ScopeContext("abc");
    String json = "{obj:{singleton:false,fields:{ic:{refer:'$conText'}}}}";
    Ioc2 ioc = new NutIoc(new MapLoader(json), context, "abc");
    TestReferContext trc = ioc.get(TestReferContext.class);
    assertTrue(context == trc.ic);

    IocContext context2 = new ScopeContext("rrr");
    trc = ioc.get(TestReferContext.class, "obj", context2);
    assertTrue(trc.ic instanceof ComboContext);
  }
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

public class ComboIocProvider implements IocProvider {

  public Ioc create(NutConfig config, String[] args) {
    try {
      return new NutIoc(new ComboIocLoader(args), new ScopeContext("app"), "app");
    }
    catch (ClassNotFoundException e) {
      throw Lang.wrapThrow(e);
    }
  }
View Full Code Here

TOP

Related Classes of org.nutz.ioc.impl.NutIoc

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.