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);
}
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();
}
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();
}
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();
}
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;
}
Aggregations