Commits

Mike Podonyi committed 5bcd209

Optimize DataContextFactory to ask for ConnectionString only when there is no DataContext in the ItemsDataStore.

  • Participants
  • Parent commits c32fa1c

Comments (0)

Files changed (1)

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

         /// </summary>
         internal DataContextFactory()
         {
-            BuildDataContext("DataContext_MetaDb", RetailerSettings.GetRetailerSettings.MetaDataBaseConnectionString);
+            BuildDataContext("DataContext_MetaDb", () => RetailerSettings.GetRetailerSettings.MetaDataBaseConnectionString);
         }
 
         /// <summary>
         /// <param name="dbState">State of the db.</param>
         internal DataContextFactory(string dbId, string dbState)
         {
-            BuildDataContext("DataContext_" + dbId+'_'+ dbState, Empi.Camino.ConnectionsStrings.GetConnectionString(dbId, dbState));
+            BuildDataContext("DataContext_" + dbId+'_'+ dbState, () => Empi.Camino.ConnectionsStrings.GetConnectionString(dbId, dbState));
         }
 
-        private void BuildDataContext(string key, string connectionString)
+
+        private void BuildDataContext(string key, Func<string> connectionString)
         {
-            DataContext = DataStoreFactory.GetItemsDataStore.LazyGet<DataContext>(key, () => (DataContext)Activator.CreateInstance(typeof(DataContext), connectionString));
+            DataContext = DataStoreFactory.GetItemsDataStore.LazyGet<DataContext>(key, () => (DataContext)Activator.CreateInstance(typeof(DataContext), connectionString()));
         }
 
         #region IDataContextFactory Members