Package org.nutz.ioc

Examples of org.nutz.ioc.IocContext


         */
        if (ioc instanceof Ioc2) {
          reqContext = new RequestIocContext(ac.getRequest());
          SessionIocContext sessionContext = new SessionIocContext(ac.getRequest()
                                        .getSession());
          IocContext myContext = new ComboContext(reqContext, sessionContext);
          obj = ((Ioc2) ioc).get(moduleType, injectName, myContext);
        }
        /*
         * 否则,则仅仅简单的从容器获取
         */
 
View Full Code Here


  public <T> T get(Class<T> type, String name, IocContext context) throws IocException {
    if (log.isDebugEnabled())
      log.debugf("Get '%s'<%s>", name, type);

    // 连接上下文
    IocContext cntx;
    if (null == context || context == this.context)
      cntx = this.context;
    else {
      if (log.isTraceEnabled())
        log.trace("Link contexts");
      cntx = new ComboContext(context, this.context);
    }

    // 创建对象创建时
    IocMaking ing = new IocMaking(this, mirrors, cntx, maker, vpms, name);

    // 从上下文缓存中获取对象代理
    ObjectProxy op = cntx.fetch(name);

    // 如果未发现对象
    if (null == op) {
      // 线程同步
      synchronized (this) {
        // 再次读取
        op = cntx.fetch(name);

        // 如果未发现对象
        if (null == op) {
          try {
            if (log.isDebugEnabled())
View Full Code Here

    IocContext ic;
  }

  @Test
  public void test_refer_context() {
    IocContext context = new ScopeContext("abc");
    String json = "{obj:{singleton:false,fields:{ic:{refer:'$conText'}}}}";
    Ioc2 ioc = new NutIoc(new MapLoader(json), context, "abc");
    TestReferContext trc = ioc.get(TestReferContext.class);
    assertTrue(context == trc.ic);

    IocContext context2 = new ScopeContext("rrr");
    trc = ioc.get(TestReferContext.class, "obj", context2);
    assertTrue(trc.ic instanceof ComboContext);
  }
View Full Code Here

       

        // 创建对象创建时
        IocMaking ing = makeIocMaking(context, name);
        IocContext cntx = ing.getContext();

        // 从上下文缓存中获取对象代理
        ObjectProxy op = cntx.fetch(name);

        // 如果未发现对象
        if (null == op) {
            // 线程同步
            synchronized (lock_get) {
                // 再次读取
                op = cntx.fetch(name);

                // 如果未发现对象
                if (null == op) {
                    try {
                        if (log.isDebugEnabled())
View Full Code Here

    /**
     * 暴露IocMaking的创建过程
     */
    public IocMaking makeIocMaking(IocContext context, String name) {
        // 连接上下文
        IocContext cntx;
        if (null == context || context == this.context)
            cntx = this.context;
        else {
            if (log.isTraceEnabled())
                log.trace("Link contexts");
View Full Code Here

                 * 如果 Ioc 容器实现了高级接口,那么会为当前请求设置上下文对象
                 */
                if (ioc instanceof Ioc2) {
                    reqContext = new RequestIocContext(ac.getRequest());
                    SessionIocContext sessionContext = new SessionIocContext(Mvcs.getHttpSession());
                    IocContext myContext = new ComboContext(reqContext, sessionContext);
                    Mvcs.setIocContext(myContext);
                    obj = ((Ioc2) ioc).get(moduleType, injectName, myContext);
                }
                /*
                 * 否则,则仅仅简单的从容器获取
 
View Full Code Here

       

        // 创建对象创建时
        IocMaking ing = makeIocMaking(context, name);
        IocContext cntx = ing.getContext();

        // 从上下文缓存中获取对象代理
        ObjectProxy op = cntx.fetch(name);

        // 如果未发现对象
        if (null == op) {
            // 线程同步
            synchronized (lock_get) {
                // 再次读取
                op = cntx.fetch(name);

                // 如果未发现对象
                if (null == op) {
                    try {
                        if (log.isDebugEnabled())
View Full Code Here

    /**
     * 暴露IocMaking的创建过程
     */
    public IocMaking makeIocMaking(IocContext context, String name) {
        // 连接上下文
        IocContext cntx;
        if (null == context || context == this.context)
            cntx = this.context;
        else {
            if (log.isTraceEnabled())
                log.trace("Link contexts");
View Full Code Here

        IocContext ic;
    }

    @Test
    public void test_refer_context() {
        IocContext context = new ScopeContext("abc");
        String json = "{obj:{singleton:false,fields:{ic:{refer:'$conText'}}}}";
        Ioc2 ioc = new NutIoc(new MapLoader(json), context, "abc");
        TestReferContext trc = ioc.get(TestReferContext.class);
        assertTrue(context == trc.ic);

        IocContext context2 = new ScopeContext("rrr");
        trc = ioc.get(TestReferContext.class, "obj", context2);
        assertTrue(trc.ic instanceof ComboContext);
    }
View Full Code Here

                 */
                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);
                    }
View Full Code Here

TOP

Related Classes of org.nutz.ioc.IocContext

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.