Commits

Mike Podonyi  committed c32fa1c

Moved Repository Creation from the Repository Subclasses to RepositoryFactory

  • Participants
  • Parent commits 6f540ea

Comments (0)

Files changed (6)

File src/Empi.Camino/Configuration/CaminoSettingsProvider.cs

 using System.Configuration;
 using Empi.Camino.Data.Retailer;
 using System.Linq;
+using Empi.Camino.Data;
 
 namespace Empi.Camino.Configuration
 {
         {
             SettingsPropertyValueCollection settingsPropertyValueCollection =new SettingsPropertyValueCollection();
             //MP:should operate on a more Common RepositoryName 
-            RetailerDataRepository<Empi.Camino.Data.IConfigurationBase> retailerDataConfiguration=RetailerDataRepository<Empi.Camino.Data.IConfigurationBase>.GetCachedRetailerDataRepository;
+            RepositoryBase<Empi.Camino.Data.IConfigurationBase> retailerDataConfiguration = RepositoryFactory.GetCachedRetailerDataRepository<Empi.Camino.Data.IConfigurationBase>();
 
             foreach(SettingsProperty settingsProperty in collection)
             {
         public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
         {
             //MP:should operate on a more Common RepositoryName
-            RetailerDataRepository<Empi.Camino.Data.IConfigurationBase> retailerDataConfiguration = RetailerDataRepository<Empi.Camino.Data.IConfigurationBase>.GetCachedRetailerDataRepository;
+            RepositoryBase<Empi.Camino.Data.IConfigurationBase> retailerDataConfiguration = RepositoryFactory.GetCachedRetailerDataRepository<Empi.Camino.Data.IConfigurationBase>();
 
             foreach (var settingsPropertyValue in from item in collection.Cast<SettingsPropertyValue>() where item.IsDirty select item)
             {

File src/Empi.Camino/ConnectionsStrings.cs

 
         internal static string GetConnectionString(string dbId, string dbState)
         {
-            var repository = Empi.Camino.Data.Meta.MetaDataRepository<Empi.Camino.Data.Meta.ConnectionStrings>.GetCachedMetaDataRepository.Single(v => ((v.Id == dbId) && (v.State == dbState)));
+            var repository = Empi.Camino.Data.RepositoryFactory.GetCachedMetaDataRepository<Empi.Camino.Data.Meta.ConnectionStrings>().Single(v => ((v.Id == dbId) && (v.State == dbState)));
             return repository.ConnectionString;
         }
     }

File src/Empi.Camino/Data/Meta/MetaDataRepository.cs

     internal class MetaDataRepository<TEntity> : RepositoryBase<TEntity>
         where TEntity : class
     {
-        private MetaDataRepository()
+        internal MetaDataRepository()
             : base(new DataContextFactory())
         {}
-
-
-        internal static MetaDataRepository<TEntity> GetMetaDataRepository
-        {
-            get
-            {
-                return new MetaDataRepository<TEntity>();
-            }
-    
-        }
-
-        internal static MetaDataRepository<TEntity> GetCachedMetaDataRepository
-        {
-            get
-            {
-                return GetMetaDataRepository;
-
-            }
-
-        }
-
-
-
-
     }
 }

File src/Empi.Camino/Data/RepositoryFactory.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Empi.Camino.Data
+{
+    /// <summary>
+    /// Builds the Repositories for Access to the Different Databases
+    /// </summary>
+    internal static class RepositoryFactory
+    {
+        //private static T GetRepository<T, V>()
+        //    where T : RepositoryBase<V>
+        //    where V : class
+        //{
+        //    return null;
+
+
+
+        //}
+
+        /// <summary>
+        /// Gets a meta data repository.
+        /// </summary>
+        /// <typeparam name="TEntity">The type of the entity.</typeparam>
+        /// <returns>Returns a repository instance ready for calling against it.</returns>
+        internal static RepositoryBase<TEntity> GetMetaDataRepository<TEntity>() where TEntity : class
+        {
+            return new Meta.MetaDataRepository<TEntity>();
+        }
+
+        /// <summary>
+        /// Gets a cached meta data repository.
+        /// </summary>
+        /// <typeparam name="TEntity">The type of the entity.</typeparam>
+        /// <returns>Returns a repository instance ready for calling against it.</returns>
+        internal static RepositoryBase<TEntity> GetCachedMetaDataRepository<TEntity>() where TEntity : class
+        {
+            return GetMetaDataRepository<TEntity>();
+        }
+
+
+        /// <summary>
+        /// Gets a retailer data repository.
+        /// </summary>
+        /// <typeparam name="TEntity">The type of the entity.</typeparam>
+        /// <returns>Returns a repository instance ready for calling against it.</returns>
+        internal static RepositoryBase<TEntity> GetRetailerDataRepository<TEntity>() where TEntity : class
+        {
+            return new Retailer.RetailerDataRepository<TEntity>();
+        }
+
+        /// <summary>
+        /// Gets a cached retailer data repository.
+        /// </summary>
+        /// <typeparam name="TEntity">The type of the entity.</typeparam>
+        /// <returns>Returns a repository instance ready for calling against it.</returns>
+        internal static RepositoryBase<TEntity> GetCachedRetailerDataRepository<TEntity>() where TEntity : class
+        {
+            return GetRetailerDataRepository<TEntity>();
+        }
+    }
+
+}

File src/Empi.Camino/Data/Retailer/RetailerDataRepository.cs

         where TEntity:class
     {
         //MP: double check if the DbId belongs really to an Retailer Database belongs really to a Retailer Repository
-        private RetailerDataRepository()
+        internal RetailerDataRepository()
             : base(new DataContextFactory(RetailerSettings.GetRetailerSettings.MyDbId, RetailerSettings.GetRetailerSettings.MyDbState))
         {}
 
 
-        internal static RetailerDataRepository<TEntity> GetRetailerDataRepository
-        {
-            get
-            {
-                return new RetailerDataRepository<TEntity>();
-    
-            }
-    
-        }
-
-        internal static RetailerDataRepository<TEntity> GetCachedRetailerDataRepository
-        {
-            get
-            {
-                return GetRetailerDataRepository;
-
-            }
-
-        }
 
       
     }

File src/Empi.Camino/Empi.Camino.csproj

     <Compile Include="ConnectionsStrings.cs" />
     <Compile Include="Data\DataContextFactory.cs" />
     <Compile Include="Data\IDataContextFactory.cs" />
+    <Compile Include="Data\RepositoryFactory.cs" />
     <Compile Include="DIContainer.cs" />
     <Compile Include="Prototyping.cs" />
     <Compile Include="Web\Data\ApplicationStateWrapper.cs" />