use of org.nutz.ioc.loader.annotation.AnnotationIocLoader 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.loader.annotation.AnnotationIocLoader in project nutz by nutzam.
the class SimpleIocTest method test_issue_1232.
@Test(expected = IocException.class)
public void test_issue_1232() {
Ioc ioc = null;
try {
ioc = new NutIoc(new AnnotationIocLoader("org.nutz.ioc.meta.issue1232"));
assertEquals(3, ioc.getNames().length);
ioc.get(null, "a");
} catch (IocException e) {
e.printStackTrace();
throw e;
} finally {
if (ioc != null)
ioc.depose();
}
}
use of org.nutz.ioc.loader.annotation.AnnotationIocLoader in project nutz by nutzam.
the class SimpleAopConfigureTest method aop_maker_inject.
@Test
public void aop_maker_inject() {
OneObject.COUNT = 0;
Ioc ioc = new NutIoc(new AnnotationIocLoader(getClass().getPackage().getName()));
ioc.get(BeAop.class);
ioc.get(AbcSimpleAop.class);
ioc.get(OneObject.class);
ioc.depose();
assertEquals(1, OneObject.COUNT);
}
use of org.nutz.ioc.loader.annotation.AnnotationIocLoader in project nutz by nutzam.
the class SimpleIocTest method test_error_bean.
@Test(expected = IocException.class)
public void test_error_bean() {
Ioc ioc = new NutIoc(new AnnotationIocLoader(DogMaster.class.getPackage().getName()));
try {
ioc.get(DogMaster.class);
fail("Never Success");
} catch (IocException e) {
}
ioc.get(DogMaster.class);
ioc.depose();
}
use of org.nutz.ioc.loader.annotation.AnnotationIocLoader in project nutz by nutzam.
the class ComboIocLoader method load.
public IocObject load(IocLoading loading, String name) throws ObjectLoadException {
for (IocLoader iocLoader : iocLoaders) if (iocLoader.has(name)) {
IocObject iocObject = iocLoader.load(loading, name);
if (log.isDebugEnabled()) {
// TODO 弄成更好看的格式,方便debug
String printName;
if (iocLoader instanceof AnnotationIocLoader) {
String packages = Arrays.toString(((AnnotationIocLoader) iocLoader).getPackages());
printName = "AnnotationIocLoader(packages=" + packages + ")";
} else if (JsonLoader.class.equals(iocLoader.getClass()) && ((JsonLoader) iocLoader).getPaths() != null) {
String paths = Arrays.toString(((JsonLoader) iocLoader).getPaths());
printName = "JsonLoader(paths=" + paths + ")";
} else {
printName = iocLoader.getClass().getSimpleName() + "@" + iocLoader.hashCode();
}
log.debugf("Found IocObject(%s) in %s", name, printName);
}
return iocObject;
}
throw new ObjectLoadException("Object '" + name + "' without define!");
}
Aggregations