Package org.nutz.ioc

Examples of org.nutz.ioc.Ioc


        assertEquals(5, f2.getAge());
    }

    @Test
    public void test_muilt_parent() {
        Ioc ioc = I(J("fox", "name:'P',age:10"), J("f2", "parent:'fox'"), J("f3", "parent:'f2'"));
        Animal f3 = ioc.get(Animal.class, "f3");
        assertEquals(10, f3.getAge());
    }
View Full Code Here


        assertEquals(10, f3.getAge());
    }

    @Test
    public void test_create_by_args() {
        Ioc ioc = I(J("fox", "age:10"), J("xb", "parent:'fox',args:['XiaoBai']"));
        Animal xb = ioc.get(Animal.class, "xb");
        assertEquals("XiaoBai", xb.getName());
    }
View Full Code Here

        assertEquals("XiaoBai", xb.getName());
    }

    @Test(expected = IocException.class)
    public void test_break_parent() {
        Ioc ioc = I(J("f2", "parent:'f3'"), J("f3", "parent:'f2'"));
        ioc.get(Animal.class, "f3");
    }
View Full Code Here

        ioc.get(Animal.class, "f3");
    }

    @Test(expected = IocException.class)
    public void test_break_parent2() {
        Ioc ioc = I(J("fox", "name:'P',age:10"), J("f2", "parent:'x'"), J("f3", "parent:'y'"));
        ioc.get(Animal.class, "f3");
    }
View Full Code Here

        assertTrue(loader.getName().length > 0);
    }

    @Test
    public void test_get_ioc_self() {
        Ioc ioc = I(J("iocV", "type:'org.nutz.ioc.json.pojo.IocSelf',fields:{ioc:{refer : '$iOc'}}"));
        assertEquals(ioc, ioc.get(IocSelf.class, "iocV").getIoc());
    }
View Full Code Here

        }
    }

    @Test
    public void test_simple_case() {
        Ioc ioc = new NutIoc(getNew("org/nutz/ioc/loader/xml/conf/simple.xml"));
        Bee c = ioc.get(Bee.class, "C");
        assertEquals("TheC", c.getName());
        assertEquals(15, c.getAge());
        assertEquals("TheQueen", c.getMother().getName());
        assertEquals(3, c.getFriends().size());
        assertEquals("TheA", c.getFriends().get(0).getName());
View Full Code Here

        RequestIocContext reqContext = null;
        try {
            if (null != moduleObj) {
                ac.setModule(moduleObj);
            } else {
                Ioc ioc = ac.getIoc();
                if (null == ioc)
                    throw Lang.makeThrow("Moudle with @InjectName('%s') or @IocBean('%s') but you not declare a Ioc for this app",
                                         injectName,
                                         injectName);
                Object obj;
                /*
                 * 如果 Ioc 容器实现了高级接口,那么会为当前请求设置上下文对象
                 */
                if (NutSessionListener.isSessionScopeEnable
                    && ioc instanceof Ioc2) {
                    reqContext = new RequestIocContext(ac.getRequest());
                    HttpSession sess = Mvcs.getHttpSession(false);
                    IocContext myContext = null;
                    // 如果容器可以创建 Session ...
                    if (null != sess) {
                        SessionIocContext sessionContext = new SessionIocContext(sess);
                        myContext = new ComboContext(reqContext, sessionContext);
                    }
                    // 如果容器禁止了 Session ...
                    else {
                        myContext = reqContext;
                    }
                    Mvcs.setIocContext(myContext);
                    obj = ((Ioc2) ioc).get(moduleType, injectName, myContext);
                }
                /*
                 * 否则,则仅仅简单的从容器获取
                 */
                else
                    obj = ioc.get(moduleType, injectName);
                ac.setModule(obj);

            }
            ac.setMethod(method);
            // if (log.isDebugEnabled()) //打印实际执行的Method信息
View Full Code Here

            createContext(config);

            /*
             * 检查 Ioc 容器并创建和保存它
             */
            Ioc ioc = createIoc(config, mainModule);

            /*
             * 组装UrlMapping
             */
            mapping = evalUrlMapping(config, mainModule, ioc);
View Full Code Here

        IocBy ib = mainModule.getAnnotation(IocBy.class);
        if (null != ib) {
            if (log.isDebugEnabled())
                log.debugf("@IocBy(type=%s, args=%s)", ib.type().getName(), Json.toJson(ib.args()));

            Ioc ioc = Mirror.me(ib.type()).born().create(config, ib.args());
            // 如果是 Ioc2 的实现,增加新的 ValueMaker
            if (ioc instanceof Ioc2) {
                ((Ioc2) ioc).addValueProxyMaker(new ServletValueProxyMaker(config.getServletContext()));
            }
            // 保存 Ioc 对象
View Full Code Here

        finally {
            SessionProvider sp = config.getSessionProvider();
            if (sp != null)
                sp.notifyStop();
            // If the application has Ioc, depose it
            Ioc ioc = config.getIoc();
            if (null != ioc)
                ioc.depose();
        }

        // Done, print info
        sw.stop();
        if (log.isInfoEnabled())
View Full Code Here

TOP

Related Classes of org.nutz.ioc.Ioc

Copyright © 2018 www.massapicom. 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.