Commits

Mike Podonyi committed 3019ce5

did Properties, Providers and Context Lazy and Threadsafe

  • Participants
  • Parent commits 0673ab1

Comments (0)

Files changed (3)

File src/Empi.Camino.Test/SettingsTest.cs

             StringAssert.Equals(testProperty.Name, "Retailer-Dummytest");
 
             Assert.AreEqual(typeof(string), testProperty.PropertyType);
+
+            //MP: more Tests here
         }
 	}
 }

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

 		private static readonly CaminoSectionGroup CaminoSettings = ((!Utils.IsWebApplication) ? ConfigurationManager.OpenExeConfiguration(null).GetSectionGroup("empi.camino") : WebConfigurationManager.OpenWebConfiguration(System.Web.HttpContext.Current.Request.ApplicationPath).GetSectionGroup("empi.camino")) as CaminoSectionGroup;
 		private static readonly string _metaDataBaseConnectionString = WebConfigurationManager.ConnectionStrings[CaminoSettings.MetaDb.ConnectionStringName].ConnectionString;
 
-        protected Settings()
-        {
-            SettingsProviderCollection settingsProviderCollection = new SettingsProviderCollection();
-            CaminoSettingsProvider caminoSettingsProvider = new CaminoSettingsProvider();
-            caminoSettingsProvider.Initialize("CaminoSettingsProvider", null);
-            settingsProviderCollection.Add(caminoSettingsProvider);
-            SettingsContext settingsContext = new SettingsContext();
-            settingsContext.Add("ConfigurationTableType", SettingsTableType);
-            Initialize(settingsContext,CreateSettings(), settingsProviderCollection);
-        }
-
         protected static TSettings GetSettings<TSettings>() 
             where TSettings : Settings, new()
         {
             return DataStoreFactory.GetApplicationDataStore.LazyGet<TSettings>(key, () => Settings.Synchronized(new TSettings()) as TSettings);
         }
 
-        //MP: make Propeties , Providers and Context Lazy and Threadsafe
-
         private SettingsPropertyCollection _Properties = null;
         public override SettingsPropertyCollection Properties
         {
             get
             {
-                return _Properties==null ? _Properties=CreateSettings(): _Properties;
+                if (_Properties == null)
+                {
+                    lock (this)
+                    {
+                        if (_Properties == null)
+                        {
+                            _Properties = new SettingsPropertyCollection();
+                            CreateSettings();
+                        }
+                    }
+                }
+                return _Properties;
             }
         }
 
         {
             get
             {
+                if (_Providers == null)
+                {
+                    lock (this)
+                    {
+                        if (_Providers == null)
+                        {
+                            _Providers = new SettingsProviderCollection();
+                            CaminoSettingsProvider caminoSettingsProvider = new CaminoSettingsProvider();
+                            caminoSettingsProvider.Initialize("CaminoSettingsProvider", null);
+                            _Providers.Add(caminoSettingsProvider);
+                        }
+                    }
+                }
                 return _Providers;
             }
         }
 
+        private SettingsContext _Context = null;
         public override SettingsContext Context
         {
             get
             {
-                return base.Context;
+                if (_Context == null)
+                {
+                    lock (this)
+                    {
+                        if (_Context == null)
+                        {
+                            _Context = new SettingsContext();
+                            _Context.Add("ConfigurationTableType", SettingsTableType);
+                        }
+                    }
+                }
+                return _Context;
             }
         }
 
 			}
 		}
 
-        private SettingsPropertyCollection CreateSettings()
+        private void CreateSettings()
         {
-            SettingsPropertyCollection coll = new SettingsPropertyCollection();
             foreach(PropertyInfo prop in GetSettingsProperties())
             {
-                coll.Add(CreateSetting(prop));
+                _Properties.Add(CreateSetting(prop));
             }
-
-            return coll;
         }
 
         private SettingsProperty CreateSetting(PropertyInfo propInfo)
                     property.Attributes.Add(attribute.GetType(), attribute);
                 }
             }
+
             if (!flag)
             {
                 property.SerializeAs = this.GetSerializeAs(propInfo.PropertyType);

File src/Empi.vsmdi

     </TestLinks>
   </TestList>
   <TestList name="Lists of Tests" id="8c43106b-9dc1-4907-a29f-aa66a61bf5b6">
-    <RunConfiguration id="22ff85a5-dbcb-43ea-a666-19658d911eff" name="Local Test Run" storage="localtestrun.testrunconfig" type="Microsoft.VisualStudio.TestTools.Common.TestRunConfiguration, Microsoft.VisualStudio.QualityTools.Common,   PublicKeyToken=b03f5f7f11d50a3a" />
+    <RunConfiguration id="a0f4f50d-91ef-4a6a-9952-15a1160f2816" name="NewDev55" storage="newdev55.testrunconfig" type="Microsoft.VisualStudio.TestTools.Common.TestRunConfiguration, Microsoft.VisualStudio.QualityTools.Common,   PublicKeyToken=b03f5f7f11d50a3a" />
   </TestList>
 </TestLists>