Commits

Douglas Aguiar  committed 496ffe5

separando o branch pois farei mudancas pesadas na injecao de dependencia dos repositorios

  • Participants
  • Parent commits 218c1cf
  • Branches 2.1.0.0-beta

Comments (0)

Files changed (10)

File LiteFx.NHibernate/NHibernateContextAdapter.cs

 		{
 			get
 			{
-				return SessionFactoryManager.Current.GetCurrentSession();
+				return SessionFactoryManager.GetCurrentSession();
 			}
 		}
 
+        protected SessionFactoryManager SessionFactoryManager { get; set; }
+
+        public NHibernateContextAdapter(SessionFactoryManager sessionFactoryManager)
+        {
+            SessionFactoryManager = sessionFactoryManager;
+        }
+
 		/// <summary>
 		/// Get a queryable object of an especifique entity.
 		/// </summary>

File LiteFx.Specs/RepositorySpecs/OrdinaryRepository.cs

 
     public class OrdinaryEntityRepository : RepositoryBase<Entity, int, IOrdinaryContext>, IOrdinaryEntityRepository
     {
-        protected override IOrdinaryContext Context
+        public OrdinaryEntityRepository(IOrdinaryContext context)
+            : base(context)
         {
-            get { return RepositoryAndContextStepDefinition.context; }
+
         }
     }
 }

File LiteFx.Specs/RepositorySpecs/RepositoryAndContextStepDefinition.cs

         [Given(@"a Repository")]
         public void GivenARepository()
         {
-            repository = new OrdinaryEntityRepository();
+            repository = new OrdinaryEntityRepository(context);
         }
 
         [Given(@"a mocked Context")]

File LiteFx/Repository/RepositoryBase.cs

         /// <summary>
         /// Method factory to be implemented.
         /// </summary>
-        protected abstract TContext Context { get; }
+        protected TContext Context { get; set; }
+
+        public RepositoryBase(TContext context)
+        {
+            Context = context;
+        }
     }
 
     /// <summary>
         where TContext : class, IContext<TId>
         where TId : struct, IEquatable<TId>, IComparable<TId>
     {
+        public RepositoryBase(TContext context) : base(context) { }
+
         /// <summary>
         /// Get all entities instances.
         /// </summary>

File Sample.Infrastructure/Repositories/ProductRepository.cs

 
 namespace Sample.Infrastructure.Repositories
 {
-    public class ProductRepository : RepositoryBase<Product>, IProductRepository { }
+    public class ProductRepository : RepositoryBase<Product>, IProductRepository
+    {
+        public ProductRepository(ISampleContext context) : base(context) { }
+    }
 }

File Sample.Infrastructure/Repositories/RepositoryBase.cs

     public abstract class RepositoryBase<TEntity> : RepositoryBase<TEntity, int, ISampleContext>, IRepository<TEntity>
             where TEntity : EntityBase
     {
-        private ISampleContext _context;
-        protected override ISampleContext Context
-        {
-            get { return _context ?? (_context = ServiceLocator.Current.GetInstance<ISampleContext>()); }
-        }
+        public RepositoryBase(ISampleContext context) : base(context) { }
     }
 }

File Sample.Infrastructure/SampleContext.cs

 {
     public class SampleContext : NHibernateContextAdapter<int>, ISampleContext
     {
+        public SampleContext(SessionFactoryManager sessionFactoryManager) : base(sessionFactoryManager) { }
+
         public IQueryable<Product> Products
         {
             get { return GetQueryableObject<Product>(); }

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/App_Start/NinjectWebCommon.cs

         {
             kernel.Bind<SessionFactoryManager>().To<SampleSessionFactoryManager>().InRequestScope();
 
-            kernel.Bind<ISampleContext>().To<SampleContext>().InSingletonScope();
+            kernel.Bind<ISampleContext>().To<SampleContext>().InRequestScope();
 
-            kernel.Bind<IProductRepository>().To<ProductRepository>().InSingletonScope();
+            kernel.Bind<IProductRepository>().To<ProductRepository>();                        
         }        
     }
 }