@@ -209,27 +209,19 @@ static Environment()
209209 }
210210
211211 GlobalProperties = new Dictionary < string , string > ( ) ;
212- GlobalProperties [ PropertyUseReflectionOptimizer ] = bool . TrueString ;
213- LoadGlobalPropertiesFromAppConfig ( ) ;
214- VerifyProperties ( GlobalProperties ) ;
215-
216- BytecodeProviderInstance = BuildBytecodeProvider ( GlobalProperties ) ;
217- EnableReflectionOptimizer = PropertiesHelper . GetBoolean ( PropertyUseReflectionOptimizer , GlobalProperties ) ;
218-
219- if ( EnableReflectionOptimizer )
220- {
221- log . Info ( "Using reflection optimizer" ) ;
222- }
212+ InitializeGlobalProperties ( LoadGlobalPropertiesFromAppConfig ( ) ) ;
223213 }
224214
225- private static void LoadGlobalPropertiesFromAppConfig ( )
215+ private static IHibernateConfiguration LoadGlobalPropertiesFromAppConfig ( )
226216 {
227- object config = ConfigurationManager . GetSection ( CfgXmlHelper . CfgSectionName ) ;
217+ var configuration = ConfigurationManager . OpenExeConfiguration ( @"C:\dev\OSS\nhibernate-core\src\NHibernate.Test\bin\Debug\netcoreapp2.0\NHibernate.Test.dll" ) ;
218+ object config = configuration . GetSection ( CfgXmlHelper . CfgSectionName ) ;
219+ //object config = ConfigurationManager.GetSection(CfgXmlHelper.CfgSectionName);
228220
229221 if ( config == null )
230222 {
231223 log . Info ( string . Format ( "{0} section not found in application configuration file" , CfgXmlHelper . CfgSectionName ) ) ;
232- return ;
224+ return null ;
233225 }
234226
235227 var nhConfig = config as IHibernateConfiguration ;
@@ -239,18 +231,39 @@ private static void LoadGlobalPropertiesFromAppConfig()
239231 string . Format (
240232 "{0} section handler, in application configuration file, is not IHibernateConfiguration, section ignored" ,
241233 CfgXmlHelper . CfgSectionName ) ) ;
242- return ;
234+ return null ;
243235 }
244236
245- GlobalProperties [ PropertyBytecodeProvider ] = nhConfig . ByteCodeProviderType ;
246- GlobalProperties [ PropertyUseReflectionOptimizer ] = nhConfig . UseReflectionOptimizer . ToString ( ) ;
247- if ( nhConfig . SessionFactory != null )
237+ return nhConfig ;
238+ }
239+
240+ public static void InitializeGlobalProperties ( IHibernateConfiguration nhConfig )
241+ {
242+ GlobalProperties . Clear ( ) ;
243+ GlobalProperties [ PropertyUseReflectionOptimizer ] = bool . TrueString ;
244+
245+ if ( nhConfig != null )
248246 {
249- foreach ( var kvp in nhConfig . SessionFactory . Properties )
247+ GlobalProperties [ PropertyBytecodeProvider ] = nhConfig . ByteCodeProviderType ;
248+ GlobalProperties [ PropertyUseReflectionOptimizer ] = nhConfig . UseReflectionOptimizer . ToString ( ) ;
249+ if ( nhConfig . SessionFactory != null )
250250 {
251- GlobalProperties [ kvp . Key ] = kvp . Value ;
251+ foreach ( var kvp in nhConfig . SessionFactory . Properties )
252+ {
253+ GlobalProperties [ kvp . Key ] = kvp . Value ;
254+ }
252255 }
253256 }
257+
258+ VerifyProperties ( GlobalProperties ) ;
259+
260+ BytecodeProviderInstance = BuildBytecodeProvider ( GlobalProperties ) ;
261+ EnableReflectionOptimizer = PropertiesHelper . GetBoolean ( PropertyUseReflectionOptimizer , GlobalProperties ) ;
262+
263+ if ( EnableReflectionOptimizer )
264+ {
265+ log . Info ( "Using reflection optimizer" ) ;
266+ }
254267 }
255268
256269 internal static void ResetSessionFactoryProperties ( )
0 commit comments