我使用Spring.NET作为IOCness时代码中的异常 [英] An Exception in my code when i using Spring.NET as IOCness

查看:84
本文介绍了我使用Spring.NET作为IOCness时代码中的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,请在下面查看我的异常信息:

first ,please look my exception infos in below:

exception time:2013-10-15 09:08:30,765 [1] 
exception level:ERROR 
exception class:logerror [(null)] 
SpringFactory.GetObject(adminFacade) 
 System.InvalidOperationException: root context is currently in creation. You must not call ContextRegistry.GetContext() from e.g. constructors of your singleton objects
   at Spring.Context.Support.ContextRegistry.InitializeContextIfNeeded()
   at Spring.Context.Support.ContextRegistry.GetContext()
   at Domain.common.SpringFactory.GetObject(String objectId) in F:\gitlab\huatongmis.git\HuaTongBusinessWeb\Domain\common\SpringFactory.cs:line 38





我的项目日志文件中有一些异常信息,实际上它不会让我的项目崩溃。但我把它当作一个可怕的问题。很长一段时间困惑了我。



请查看我的代码文件中的异常点。



there are some exception infos like that in my project log files,actually it does not make my project break down. but I treat it as a terrible problem.it puzzled me for a long time.

please see the exception point in my code file.

public class SpringFactory
    {
        private static IApplicationContext _applicationContext;

        private SpringFactory(){}


        public static Object GetObject(string objectId)
        {
            try
            {
                if (_applicationContext == null)
                {
                    _applicationContext = ContextRegistry.GetContext();
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(string.Format("SpringFactory.GetObject({0})",objectId), ex);
            }
            return _applicationContext.GetObject(objectId);
        }
    }





我就像这样使用IOc



I use the IOc just like this

public class Order : System.Web.Services.WebService
    {
        public HTSoapHeader htSoapHeader;
        private OrderFacade orderFacade { get; set; }
        private TicketFacade ticketFacade { get; set; }
        private CarrentalFacade carrentalFacade { get; set; }
        private AdminFacade adminFacade { get; set; }
        public Order()
        {
            orderFacade = (OrderFacade)SpringFactory.GetObject("orderFacade");
            ticketFacade = (TicketFacade)SpringFactory.GetObject("ticketFacade");
            carrentalFacade = (CarrentalFacade)SpringFactory.GetObject("carrentalFacade");
            adminFacade = (AdminFacade)SpringFactory.GetObject("adminFacade");
        }
}





如何发生以及如何解决问题。

期待得到你的答案,谢谢



how it happened and how to solve the problem.
looking forward to having your any answer, thanks

推荐答案

谢谢你的答案,我找到了导致该异常的根本原因。这是我的IIS.my项目在iis7.0上使用integrerad管道模式进行了解释。但是在弹簧IOC容器的初始化期间,有一个重写Httpcontext的动作。遗憾的是,在应用程序的管道事件中,例如Global的构造函数和Application_Start事件.httpcontext未在IIS7.0 integrerad管道模式下初始化。这是给出例外的根本原因。
thank u for you answer,I found the root cause which result in that exception.It's my IIS.my project is deploied on iis7.0 with integrerad pipeline mode.But during initialization of the spring IOC container,there is a action that rewriting Httpcontext.Unfortunately, In the pipe events of application such as the constructor of Global,and the Application_Start event.the httpcontext is not initialized under The IIS7.0 integrerad pipeline mode. that is the root cause which giving the exception.


这篇关于我使用Spring.NET作为IOCness时代码中的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆