@@ -209,27 +209,18 @@ 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 ( Assembly . GetEntryAssembly ( ) . Location ) ;
218+ object config = configuration . GetSection ( CfgXmlHelper . CfgSectionName ) ;
228219
229220 if ( config == null )
230221 {
231222 log . Info ( string . Format ( "{0} section not found in application configuration file" , CfgXmlHelper . CfgSectionName ) ) ;
232- return ;
223+ return null ;
233224 }
234225
235226 var nhConfig = config as IHibernateConfiguration ;
@@ -239,18 +230,39 @@ private static void LoadGlobalPropertiesFromAppConfig()
239230 string . Format (
240231 "{0} section handler, in application configuration file, is not IHibernateConfiguration, section ignored" ,
241232 CfgXmlHelper . CfgSectionName ) ) ;
242- return ;
233+ return null ;
243234 }
244235
245- GlobalProperties [ PropertyBytecodeProvider ] = nhConfig . ByteCodeProviderType ;
246- GlobalProperties [ PropertyUseReflectionOptimizer ] = nhConfig . UseReflectionOptimizer . ToString ( ) ;
247- if ( nhConfig . SessionFactory != null )
236+ return nhConfig ;
237+ }
238+
239+ public static void InitializeGlobalProperties ( IHibernateConfiguration nhConfig )
240+ {
241+ GlobalProperties . Clear ( ) ;
242+ GlobalProperties [ PropertyUseReflectionOptimizer ] = bool . TrueString ;
243+
244+ if ( nhConfig != null )
248245 {
249- foreach ( var kvp in nhConfig . SessionFactory . Properties )
246+ GlobalProperties [ PropertyBytecodeProvider ] = nhConfig . ByteCodeProviderType ;
247+ GlobalProperties [ PropertyUseReflectionOptimizer ] = nhConfig . UseReflectionOptimizer . ToString ( ) ;
248+ if ( nhConfig . SessionFactory != null )
250249 {
251- GlobalProperties [ kvp . Key ] = kvp . Value ;
250+ foreach ( var kvp in nhConfig . SessionFactory . Properties )
251+ {
252+ GlobalProperties [ kvp . Key ] = kvp . Value ;
253+ }
252254 }
253255 }
256+
257+ VerifyProperties ( GlobalProperties ) ;
258+
259+ BytecodeProviderInstance = BuildBytecodeProvider ( GlobalProperties ) ;
260+ EnableReflectionOptimizer = PropertiesHelper . GetBoolean ( PropertyUseReflectionOptimizer , GlobalProperties ) ;
261+
262+ if ( EnableReflectionOptimizer )
263+ {
264+ log . Info ( "Using reflection optimizer" ) ;
265+ }
254266 }
255267
256268 internal static void ResetSessionFactoryProperties ( )
0 commit comments