Search in sources :

Example 1 with AnnotationIocLoader

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);
}
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 2 with AnnotationIocLoader

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();
    }
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) AnnotationIocLoader(org.nutz.ioc.loader.annotation.AnnotationIocLoader) NutIoc(org.nutz.ioc.impl.NutIoc) Test(org.junit.Test)

Example 3 with AnnotationIocLoader

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);
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) AnnotationIocLoader(org.nutz.ioc.loader.annotation.AnnotationIocLoader) Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc) Test(org.junit.Test)

Example 4 with AnnotationIocLoader

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();
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) AnnotationIocLoader(org.nutz.ioc.loader.annotation.AnnotationIocLoader) NutIoc(org.nutz.ioc.impl.NutIoc) DogMaster(org.nutz.ioc.meta.issue348.DogMaster) Test(org.junit.Test)

Example 5 with AnnotationIocLoader

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!");
}
Also used : AnnotationIocLoader(org.nutz.ioc.loader.annotation.AnnotationIocLoader) ObjectLoadException(org.nutz.ioc.ObjectLoadException) IocObject(org.nutz.ioc.meta.IocObject) XmlIocLoader(org.nutz.ioc.loader.xml.XmlIocLoader) IocLoader(org.nutz.ioc.IocLoader) AsyncAopIocLoader(org.nutz.aop.interceptor.async.AsyncAopIocLoader) AnnotationIocLoader(org.nutz.ioc.loader.annotation.AnnotationIocLoader) PropertiesIocLoader(org.nutz.ioc.loader.properties.PropertiesIocLoader) TransIocLoader(org.nutz.aop.interceptor.ioc.TransIocLoader) JsonLoader(org.nutz.ioc.loader.json.JsonLoader)

Aggregations

AnnotationIocLoader (org.nutz.ioc.loader.annotation.AnnotationIocLoader)5 Test (org.junit.Test)4 NutIoc (org.nutz.ioc.impl.NutIoc)4 AsyncAopIocLoader (org.nutz.aop.interceptor.async.AsyncAopIocLoader)1 TransIocLoader (org.nutz.aop.interceptor.ioc.TransIocLoader)1 Ioc (org.nutz.ioc.Ioc)1 IocLoader (org.nutz.ioc.IocLoader)1 ObjectLoadException (org.nutz.ioc.ObjectLoadException)1 JsonLoader (org.nutz.ioc.loader.json.JsonLoader)1 PropertiesIocLoader (org.nutz.ioc.loader.properties.PropertiesIocLoader)1 XmlIocLoader (org.nutz.ioc.loader.xml.XmlIocLoader)1 IocObject (org.nutz.ioc.meta.IocObject)1 DogMaster (org.nutz.ioc.meta.issue348.DogMaster)1 Issue399Service (org.nutz.ioc.meta.issue399.Issue399Service)1