Commits

Douglas Aguiar  committed b2c7206

melhorias no sessionper request

  • Participants
  • Parent commits 0ebb3a3
  • Branches 1.4.0.0-beta

Comments (0)

Files changed (5)

File LiteFx.NHibernate/SessionFactoryManager.cs

 			}
 		}
 
-		public SessionFactoryManager()
-		{
-			id = Guid.NewGuid();
-		}
-
 		private Guid id;
 		public Guid Id { get { return id; } }
 
+        public bool ReadOnly { get; set; }
+
+        private ISession session;
 
 		private static Mutex _factoryMutex = new Mutex();
 
 			}
 		}
 
+        public SessionFactoryManager()
+        {
+            id = Guid.NewGuid();
+        }
+        
         public static void Initialize() 
         {
             if (sessionFactory != null)
             }
         }
 
-        public bool ReadOnly { get; set; }
-
-		private ISession session;
-
 		public virtual ISession GetCurrentSession()
 		{
 			if (session == null)
 
                 Trace.WriteLine("Opening NHibernate Session.", "LiteFx");
 				session = SessionFactory.OpenSession();
+				//CurrentSessionContext.Bind(session);
 
-                session.DefaultReadOnly = ReadOnly;
+                if (ReadOnly)
+                {
+                    session.DefaultReadOnly = true;
+                    session.FlushMode = FlushMode.Never;
+                }
+                else
+                {
+                    BeginTransaction();
+                }
+			}
 
-                if (!ReadOnly)
+			return session;
+		}
+
+        private void BeginTransaction()
+        {
+            if (session != null)
+            {
+                if (!session.Transaction.IsActive)
                 {
                     Trace.WriteLine("Beggining NHibernate Transaction.", "LiteFx");
                     session.BeginTransaction();
                 }
-				//CurrentSessionContext.Bind(session);
-			}
-
-			return session;
-		}
+            }
+        }
 
 		public virtual void DisposeSession()
 		{

File Sample.Web.Mvc/App_Data/SampleDB.mdf

Binary file modified.

File Sample.Web.Mvc/App_Data/SampleDB_log.ldf

Binary file modified.

File Sample.Web.Mvc/Sample.Web.Mvc.csproj

     <Content Include="Scripts\respond.js" />
     <Content Include="Scripts\respond.min.js" />
     <Content Include="Scripts\_references.js" />
-    <Content Include="Web.config" />
+    <Content Include="Web.config">
+      <SubType>Designer</SubType>
+    </Content>
     <Content Include="Web.Debug.config">
       <DependentUpon>Web.config</DependentUpon>
     </Content>

File Sample.Web.Mvc/Web.config

     <add key="UnobtrusiveJavaScriptEnabled" value="true" />
   </appSettings>
   <system.web>
-    <trace enabled="true" pageOutput="false"/>
+    <trace enabled="true" pageOutput="true" mostRecent="true"/>
     <compilation debug="true" targetFramework="4.5" />
     <httpRuntime targetFramework="4.5" />
   </system.web>