private SimpleSessionStorage GetSimpleSessionStorageForThread()
        {
            var currentThreadName = this.GetCurrentThreadName();
            SimpleSessionStorage sessionStorage;
            if (!this.perThreadSessionStorage.TryGetValue(currentThreadName, out sessionStorage))
            {
                sessionStorage = new SimpleSessionStorage();
                this.perThreadSessionStorage.Add(currentThreadName, sessionStorage);
            }

            return sessionStorage;
        }
        private static ISessionStorage GetSessionStorage()
        {
            HttpContext current = HttpContext.Current;

            if(current != null)
            {
                var simpleSessionStorage = current.Items[HttpContextSessionStorageKey] as SimpleSessionStorage;
                if (simpleSessionStorage == null)
                {
                    simpleSessionStorage = new SimpleSessionStorage();
                    current.Items[HttpContextSessionStorageKey] = simpleSessionStorage;
                }
                return simpleSessionStorage;
            }
            return GetStorageForThread();
        }
示例#3
0
        public static Configuration Init(SimpleSessionStorage storage,
                                         string connectionString, Assembly mappingsAssembly, string mappingsNamespace,
                                         string validationDefinitionsNamespace, bool showLogs, string outputXmlMappingsFile,
                                         Type baseEntityToIgnore, bool mapAllEnumsToStrings, Action <ModelMapper> autoMappingOverride)
        {
            InitStorage(storage);

            try
            {
                var configuration = ReadConfigFromCacheFileOrBuildIt(mappingsAssembly, connectionString, showLogs,
                                                                     baseEntityToIgnore, mappingsNamespace, mapAllEnumsToStrings, autoMappingOverride, outputXmlMappingsFile, validationDefinitionsNamespace);
                var sessionFactory = configuration.BuildSessionFactory();

                return(AddConfiguration(DefaultFactoryKey, sessionFactory, configuration, string.Empty));
            }
            catch
            {
                // If this NHibernate config throws an exception, null the Storage reference so
                // the config can be corrected without having to restart the web application.
                Storage = null;
                throw;
            }
        }
 private static ISessionStorage GetStorageForThread()
 {
     var simpleSessionStorage = Thread.GetData(Slot) as SimpleSessionStorage;
     if (simpleSessionStorage == null)
     {
         simpleSessionStorage = new SimpleSessionStorage();
         Thread.SetData(Slot, simpleSessionStorage);
     }
     return simpleSessionStorage;
 }