때때로 나는 내 웹 응용 프로그램에서이 오류 스택 추적을 얻을 : 내 응용 프로그램에서 또한SessionFactory를 스레드 안전 문제
public interface ISessionFactoryProvider
{
ISessionFactory GetSessionFactory();
}
public abstract class BaseSessionFactoryProvider : ISessionFactoryProvider
{
protected readonly ISessionFactory factory;
public ISessionFactory GetSessionFactory()
{
return factory;
}
protected BaseSessionFactoryProvider()
{
factory = GetConfig().BuildSessionFactory();
}
public abstract Configuration GetConfig();
}
public class SessionFactoryProvider : BaseSessionFactoryProvider
{
public static ISessionFactory SessionFactory
{
get { return Instance.factory; }
}
public override Configuration GetConfig()
{
return new Configuration().Configure();
}
public static SessionFactoryProvider Instance
{
get
{
return NestedSessionManager.sessionManager;
}
}
class NestedSessionManager
{
internal static readonly SessionFactoryProvider sessionManager =
new SessionFactoryProvider();
}
}
내가 ISessionFactoryProvider에 SessionFactoryProvider 바인딩 :
[ArgumentException: An item with the same key has already been added.]
System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) +52
System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) +10695474
System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value) +10
NHibernate.Util.ThreadSafeDictionary`2.Add(TKey key, TValue value) +93
NHibernate.Type.TypeFactory.GetType(NullableType defaultUnqualifiedType, Int32 length, GetNullableTypeWithLength ctorDelegate) +88
NHibernate.Type.TypeFactory.<RegisterDefaultNetTypes>b__c(Int32 l) +82
NHibernate.Type.TypeFactory.BuiltInType(String typeName, Int32 length) +46
NHibernate.Mapping.SimpleValue.GetHeuristicType() +168
NHibernate.Mapping.SimpleValue.get_Type() +49
NHibernate.Mapping.SimpleValue.IsValid(IMapping mapping) +30
NHibernate.Mapping.PersistentClass.Validate(IMapping mapping) +87
NHibernate.Mapping.RootClass.Validate(IMapping mapping) +21
NHibernate.Cfg.Configuration.ValidateEntities() +183
NHibernate.Cfg.Configuration.Validate() +13
NHibernate.Cfg.Configuration.BuildSessionFactory() +36
Framework.Data.Code.BaseSessionFactoryProvider..ctor() +74
Framework.Data.Code.SessionFactoryProvider..ctor() +29
Framework.Data.Code.NestedSessionManager..cctor() +43
내 SessionFactoryProvider는 스레드 안전 singletone입니다 ninject 통해 kernel.Bind<ISessionFactoryProvider>().To<SessionFactoryProvider>().InSingletonScope();
그래서 내 질문 왜이 오류가 발생합니까?
스택 추적에서'ThreadSafeDictionary'를 오도하지 마십시오. 나는 이것이 스레딩 문제라고 생각하지 않는다. 이것은 NHibernate 매핑에 문제가있을 가능성이 큽니다. 동일한 클래스 이름을 가진 두 개의 엔티티가 있습니까? 아마도 다른 네임 스페이스에 있습니까? –
@DanielSchilling 중복 매핑 인 경우 오류가 항상 표시되지 않고 '가끔'표시되지 않습니까? – jbl
나는 대답이 없다는 것이 두렵다 ...하지만 당신은 상속과 함께 http://csharpindepth.com/Articles/General/Singleton.aspx#nested-cctor의 약간 다른 버전을 혼합하는 것 같다. 나는 여기에 어떤 결함도 보이지 않는다 (그러나 나는 C# 닌자가 아니다). 또한이를 IOC 싱글 톤 구현과 섞습니다. 문제는 여기에있을 것 같아요, 당신은 싱글 톤 구현을 위해서만 IOC에 의존해야합니다. – jbl