@@ -209,27 +209,18 @@ static Environment()
209
209
}
210
210
211
211
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 ( ) ) ;
223
213
}
224
214
225
- private static void LoadGlobalPropertiesFromAppConfig ( )
215
+ private static IHibernateConfiguration LoadGlobalPropertiesFromAppConfig ( )
226
216
{
227
- object config = ConfigurationManager . GetSection ( CfgXmlHelper . CfgSectionName ) ;
217
+ var configuration = ConfigurationManager . OpenExeConfiguration ( Assembly . GetEntryAssembly ( ) . Location ) ;
218
+ object config = configuration . GetSection ( CfgXmlHelper . CfgSectionName ) ;
228
219
229
220
if ( config == null )
230
221
{
231
222
log . Info ( string . Format ( "{0} section not found in application configuration file" , CfgXmlHelper . CfgSectionName ) ) ;
232
- return ;
223
+ return null ;
233
224
}
234
225
235
226
var nhConfig = config as IHibernateConfiguration ;
@@ -239,18 +230,39 @@ private static void LoadGlobalPropertiesFromAppConfig()
239
230
string . Format (
240
231
"{0} section handler, in application configuration file, is not IHibernateConfiguration, section ignored" ,
241
232
CfgXmlHelper . CfgSectionName ) ) ;
242
- return ;
233
+ return null ;
243
234
}
244
235
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 )
248
245
{
249
- foreach ( var kvp in nhConfig . SessionFactory . Properties )
246
+ GlobalProperties [ PropertyBytecodeProvider ] = nhConfig . ByteCodeProviderType ;
247
+ GlobalProperties [ PropertyUseReflectionOptimizer ] = nhConfig . UseReflectionOptimizer . ToString ( ) ;
248
+ if ( nhConfig . SessionFactory != null )
250
249
{
251
- GlobalProperties [ kvp . Key ] = kvp . Value ;
250
+ foreach ( var kvp in nhConfig . SessionFactory . Properties )
251
+ {
252
+ GlobalProperties [ kvp . Key ] = kvp . Value ;
253
+ }
252
254
}
253
255
}
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
+ }
254
266
}
255
267
256
268
internal static void ResetSessionFactoryProperties ( )
0 commit comments