Search in sources :

Example 6 with NutIoc

use of org.nutz.ioc.impl.NutIoc in project nutz by nutzam.

the class SimpleIocTest method test_no_singleton_depose.

@Test
public void test_no_singleton_depose() {
    Issue399Service.CreateCount = 0;
    Issue399Service.DeposeCount = 0;
    Ioc ioc = new NutIoc(new AnnotationIocLoader(Issue399Service.class.getPackage().getName()));
    for (int i = 0; i < 100; i++) {
        ioc.get(Issue399Service.class);
    }
    assertEquals(1, ioc.getNamesByType(Issue399Service.class).length);
    ioc.getByType(Issue399Service.class);
    ioc.depose();
    System.gc();
    assertEquals(101, Issue399Service.CreateCount);
    assertEquals(0, Issue399Service.DeposeCount);
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) AnnotationIocLoader(org.nutz.ioc.loader.annotation.AnnotationIocLoader) NutIoc(org.nutz.ioc.impl.NutIoc) Issue399Service(org.nutz.ioc.meta.issue399.Issue399Service) Test(org.junit.Test)

Example 7 with NutIoc

use of org.nutz.ioc.impl.NutIoc in project nutz by nutzam.

the class AopJsonIocTest method test_simple.

@Test
public void test_simple() {
    Nutzs.cd();
    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();
    fox.getName();
    assertEquals("B:getName0;A:getName0;B:getName0;A:getName0;", sb.toString());
    ioc.depose();
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) Mammal(org.nutz.ioc.json.pojo.Mammal) IocLoader(org.nutz.ioc.IocLoader) JsonLoader(org.nutz.ioc.loader.json.JsonLoader) Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc) Test(org.junit.Test)

Example 8 with NutIoc

use of org.nutz.ioc.impl.NutIoc in project nutz by nutzam.

the class PlugsTest method test_get_plugin_from_ioc.

@Test
public void test_get_plugin_from_ioc() {
    Ioc ioc = new NutIoc(new JsonLoader("org/nutz/plugin/plugin.js"));
    PluginManager<Log> manager = new IocPluginManager<Log>(ioc, "pluB", "pluA", "pluC");
    assertNotNull(manager.get());
    assertTrue(manager.get() instanceof SystemLogAdapter);
    ioc.depose();
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) Log(org.nutz.log.Log) SystemLogAdapter(org.nutz.log.impl.SystemLogAdapter) JsonLoader(org.nutz.ioc.loader.json.JsonLoader) Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc) Test(org.junit.Test)

Example 9 with NutIoc

use of org.nutz.ioc.impl.NutIoc in project nutz by nutzam.

the class BaseNutTest method init.

/**
     * 初始化Ioc容器
     * @throws Exception 初始化过程出错的话抛错
     */
@Before
public void init() throws Exception {
    // 生成Ioc容器
    ioc = new NutIoc(getIocLoader());
    // 注入自身字段
    _init_fields();
    // 执行用户自定义初始化过程
    _init();
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) Before(org.junit.Before)

Example 10 with NutIoc

use of org.nutz.ioc.impl.NutIoc in project nutz by nutzam.

the class Nutzs method getIoc.

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) {
                    nut = new NutIoc(new JsonLoader(key));
                    nuts.put(key, nut);
                }
            } catch (Exception e) {
                throw Lang.wrapThrow(e);
            }
        }
    }
    return nut;
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) JsonLoader(org.nutz.ioc.loader.json.JsonLoader) Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc)

Aggregations

NutIoc (org.nutz.ioc.impl.NutIoc)20 Test (org.junit.Test)16 Ioc (org.nutz.ioc.Ioc)10 JsonLoader (org.nutz.ioc.loader.json.JsonLoader)6 MapLoader (org.nutz.ioc.loader.map.MapLoader)6 AnnotationIocLoader (org.nutz.ioc.loader.annotation.AnnotationIocLoader)4 Ioc2 (org.nutz.ioc.Ioc2)3 IocContext (org.nutz.ioc.IocContext)2 IocLoader (org.nutz.ioc.IocLoader)2 ScopeContext (org.nutz.ioc.impl.ScopeContext)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Before (org.junit.Before)1 NutDao (org.nutz.dao.impl.NutDao)1 Pet (org.nutz.dao.test.meta.Pet)1 IocMaking (org.nutz.ioc.IocMaking)1 ObjectProxy (org.nutz.ioc.ObjectProxy)1 ValueProxy (org.nutz.ioc.ValueProxy)1 ValueProxyMaker (org.nutz.ioc.ValueProxyMaker)1 ComboContext (org.nutz.ioc.impl.ComboContext)1