diff Agendas/trunk/src/Agendas.NHibernate/SessionScope.cs @ 179:1deccd6c3cb2

Aplicando seguridad x roles en sitio web
author nelopauselli
date Mon, 08 Aug 2011 15:24:26 -0300
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.NHibernate/SessionScope.cs	Mon Aug 08 15:24:26 2011 -0300
@@ -0,0 +1,27 @@
+using System;
+using NHibernate;
+using NHibernate.Context;
+
+namespace Agendas.NHibernate
+{
+	public class SessionScope : IDisposable
+	{
+		private readonly ISessionFactory _sessionFactory;
+
+		public SessionScope(ISessionFactory sessionFactory)
+		{
+			_sessionFactory = sessionFactory;
+
+			var session = _sessionFactory.OpenSession();
+			CurrentSessionContext.Bind(session);
+		}
+
+		public void Dispose()
+		{
+			var session = _sessionFactory.GetCurrentSession();
+
+			session.Flush();
+			session.Close();
+		}
+	}
+}
\ No newline at end of file