Commits

Douglas Aguiar committed 218c1cf

diposable no sessionfactorymanager

Comments (0)

Files changed (2)

LiteFx.NHibernate/SessionFactoryManager.cs

 
 namespace LiteFx.Context.NHibernate
 {
-    public abstract class SessionFactoryManager
+    public abstract class SessionFactoryManager : IDisposable
     {
         public static SessionFactoryManager Current
         {
             }
         }
 
+        #region IDisposable Members [Dispose pattern implementation]
+
+		/// <summary>
+		/// Implementação do Dipose Pattern.
+		/// </summary>
+		/// <remarks><a target="blank" href="http://msdn.microsoft.com/en-us/library/fs2xkftw.aspx">Dispose Pattern</a>.</remarks>
+		private bool disposed;
+
+		/// <summary>
+		/// Libera todos os recursos utilizados pela classe.
+		/// Implementação do Dispose Pattern.
+		/// </summary>
+		/// <remarks><a target="blank" href="http://msdn.microsoft.com/en-us/library/fs2xkftw.aspx">Dispose Pattern</a>.</remarks>
+		/// <param name="disposing">Usado para verificar se a chamada esta sendo feita pelo <see cref="GC"/> ou pela aplicação.</param>
+		protected virtual void Dispose(bool disposing)
+		{
+			if (disposed) return;
+
+			if (disposing)
+			{
+				if (session != null)
+					session.Dispose();
+			}
+
+			disposed = true;
+		}
+
+		/// <summary>
+		/// Chamado pelo <see ref="GC" /> para liberar recursos que não estão sendo utilizados.
+		/// Implementação do Dipose Pattern.
+		/// </summary>
+		/// <remarks><a target="blank" href="http://msdn.microsoft.com/en-us/library/fs2xkftw.aspx">Dispose Pattern</a>.</remarks>
+        ~SessionFactoryManager()
+		{
+			Dispose(false);
+		}
+
+		/// <summary>
+		/// Libera todos os recursos utilizados pela classe.
+		/// Implementação do Dipose Pattern.
+		/// </summary>
+		/// <remarks><a target="blank" href="http://msdn.microsoft.com/en-us/library/fs2xkftw.aspx">Dispose Pattern</a>.</remarks>
+		public void Dispose()
+		{
+			Dispose(true);
+			GC.SuppressFinalize(this);
+		}
+		#endregion
+
         string _traceCategory = string.Empty;
 
         private string getTraceCategory()

Sample.Web.Mvc/App_Start/NinjectWebCommon.cs

             var ninjectServiceLocator = new NinjectAdapter.NinjectServiceLocator(kernel);
             ServiceLocator.SetLocatorProvider(() => ninjectServiceLocator);
 
-            //ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory(kernel));
-
             RegisterServices(kernel);
             return kernel;
         }
         /// <param name="kernel">The kernel.</param>
         private static void RegisterServices(IKernel kernel)
         {
-            kernel.Bind<SessionFactoryManager>().To<SampleSessionFactoryManager>().InRequestScope();//.InThreadScope();//.InRequestScope<SampleSessionFactoryManager>();
+            kernel.Bind<SessionFactoryManager>().To<SampleSessionFactoryManager>().InRequestScope();
 
             kernel.Bind<ISampleContext>().To<SampleContext>().InSingletonScope();
 
-            kernel.Bind<IProductRepository>().To<ProductRepository>();
+            kernel.Bind<IProductRepository>().To<ProductRepository>().InSingletonScope();
         }        
     }
-
-    public class NinjectControllerFactory : DefaultControllerFactory
-    {
-        private IKernel kernel;
-
-        public NinjectControllerFactory(IKernel kernel)
-        {
-            this.kernel = kernel;
-        }
-
-
-        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
-        {
-            if (controllerType == null)
-                throw new HttpException(404, String.Format("The controller for path '{0}' could not be found or it does not implement IController.", requestContext.HttpContext.Request.Path));
-
-            return (IController)kernel.Get(controllerType);
-        }
-    }
 }