Examples of Ioc2


Examples of org.nutz.ioc.Ioc2

public class ScopeJsonIocTest {

  @Test
  public void test_simple_scope() {
    Ioc2 ioc = IJ("f1", "scope:'app',fields:{name:'F1'}"),
            J("f2", "scope:'MyScope',fields:{name:'F2'}"));

    Animal f1 = ioc.get(Animal.class, "f1");
    assertEquals("F1", f1.getName());

    Animal f2 = ioc.get(Animal.class, "f2");
    assertEquals("F2", f2.getName());
    Animal f22 = ioc.get(Animal.class, "f2");
    assertEquals("F2", f22.getName());
    assertFalse(f2 == f22);

    ScopeContext ic = new ScopeContext("MyScope");
    Map<String, ObjectProxy> map = ic.getObjs();
    f2 = ioc.get(Animal.class, "f2", ic);
    assertEquals("F2", f2.getName());
    f22 = ioc.get(Animal.class, "f2", ic);
    assertEquals("F2", f22.getName());
    assertTrue(f2 == f22);
    assertEquals(1, map.size());

    ioc.get(Animal.class, "f1", ic);

    assertEquals(1, map.size());

  }
View Full Code Here

Examples of org.nutz.ioc.Ioc2

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

Examples of org.nutz.ioc.Ioc2

  }
 
  @Test
  public void test_refer_from_diffenent_scope(){
    Ioc2 ioc = IJ("f1", "type : 'org.nutz.ioc.json.pojo.Animal' , scope:'app',fields:{name:'F1'}"),
            J("f2", "type : 'org.nutz.ioc.json.pojo.Animal' , scope:'MyScope',fields:{name:{refer : 'f3'}}"),
            J("f3", "type : 'org.nutz.ioc.json.pojo.Animal' , scope:'MyScope'}"));
    ioc.get(null, "f2");
  }
View Full Code Here

Examples of org.nutz.ioc.Ioc2

  @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

Examples of org.nutz.ioc.Ioc2

public class ScopeJsonIocTest {

    @Test
    public void test_simple_scope() {
        Ioc2 ioc = I(    J("f1", "scope:'app',fields:{name:'F1'}"),
                        J("f2", "scope:'MyScope',fields:{name:'F2'}"));

        Animal f1 = ioc.get(Animal.class, "f1");
        assertEquals("F1", f1.getName());

        Animal f2 = ioc.get(Animal.class, "f2");
        assertEquals("F2", f2.getName());
        Animal f22 = ioc.get(Animal.class, "f2");
        assertEquals("F2", f22.getName());
        assertFalse(f2 == f22);

        ScopeContext ic = new ScopeContext("MyScope");
        Map<String, ObjectProxy> map = ic.getObjs();
        f2 = ioc.get(Animal.class, "f2", ic);
        assertEquals("F2", f2.getName());
        f22 = ioc.get(Animal.class, "f2", ic);
        assertEquals("F2", f22.getName());
        assertTrue(f2 == f22);
        assertEquals(1, map.size());

        ioc.get(Animal.class, "f1", ic);

        assertEquals(1, map.size());

    }
View Full Code Here

Examples of org.nutz.ioc.Ioc2

    }
   
    @Test
    public void test_refer_from_diffenent_scope(){
        Ioc2 ioc = I(    J("f1", "type : 'org.nutz.ioc.json.pojo.Animal' , scope:'app',fields:{name:'F1'}"),
                        J("f2", "type : 'org.nutz.ioc.json.pojo.Animal' , scope:'MyScope',fields:{name:{refer : 'f3'}}"),
                        J("f3", "type : 'org.nutz.ioc.json.pojo.Animal' , scope:'MyScope'}"));
        ioc.get(null, "f2");
    }
View Full Code Here

Examples of org.nutz.ioc.Ioc2

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

Examples of org.nutz.ioc.Ioc2

    @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
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.