@@ -187,11 +187,8 @@ private void NotifyDisposing()
187
187
/// }
188
188
/// </code></sample>
189
189
/// <seealso cref="Session"/>
190
- public Session OpenSession ( )
191
- {
192
- var configuration = Configuration . Sessions . Default ;
193
- return OpenSession ( configuration ) ;
194
- }
190
+ public Session OpenSession ( ) =>
191
+ OpenSession ( Configuration . Sessions . Default ) ;
195
192
196
193
/// <summary>
197
194
/// Opens new <see cref="Session"/> of specified <see cref="SessionType"/>.
@@ -205,21 +202,8 @@ public Session OpenSession()
205
202
/// // work with persistent objects here.
206
203
/// }
207
204
/// </code></sample>
208
- public Session OpenSession ( SessionType type )
209
- {
210
- switch ( type ) {
211
- case SessionType . User :
212
- return OpenSession ( Configuration . Sessions . Default ) ;
213
- case SessionType . System :
214
- return OpenSession ( Configuration . Sessions . System ) ;
215
- case SessionType . KeyGenerator :
216
- return OpenSession ( Configuration . Sessions . KeyGenerator ) ;
217
- case SessionType . Service :
218
- return OpenSession ( Configuration . Sessions . Service ) ;
219
- default :
220
- throw new ArgumentOutOfRangeException ( "type" ) ;
221
- }
222
- }
205
+ public Session OpenSession ( SessionType type ) =>
206
+ OpenSession ( GetSessionConfiguration ( type ) ) ;
223
207
224
208
/// <summary>
225
209
/// Opens new <see cref="Session"/> with specified <see cref="SessionConfiguration"/>.
@@ -234,14 +218,8 @@ public Session OpenSession(SessionType type)
234
218
/// }
235
219
/// </code></sample>
236
220
/// <seealso cref="Session"/>
237
- public Session OpenSession ( SessionConfiguration configuration )
238
- {
239
- ArgumentValidator . EnsureArgumentNotNull ( configuration , "configuration" ) ;
240
-
241
- return OpenSessionInternal ( configuration ,
242
- null ,
243
- configuration . Supports ( SessionOptions . AutoActivation ) ) ;
244
- }
221
+ public Session OpenSession ( SessionConfiguration configuration ) =>
222
+ OpenSessionInternal ( configuration , null , configuration . Supports ( SessionOptions . AutoActivation ) ) ;
245
223
246
224
internal Session OpenSessionInternal ( SessionConfiguration configuration , StorageNode storageNode , bool activate )
247
225
{
@@ -283,11 +261,8 @@ internal Session OpenSessionInternal(SessionConfiguration configuration, Storage
283
261
/// }
284
262
/// </code></sample>
285
263
/// <seealso cref="Session"/>
286
- public Task < Session > OpenSessionAsync ( CancellationToken cancellationToken = default )
287
- {
288
- var configuration = Configuration . Sessions . Default ;
289
- return OpenSessionAsync ( configuration , cancellationToken ) ;
290
- }
264
+ public Task < Session > OpenSessionAsync ( CancellationToken cancellationToken = default ) =>
265
+ OpenSessionAsync ( Configuration . Sessions . Default , cancellationToken ) ;
291
266
292
267
/// <summary>
293
268
/// Opens new <see cref="Session"/> of specified <see cref="SessionType"/> asynchronously.
@@ -304,18 +279,7 @@ public Task<Session> OpenSessionAsync(CancellationToken cancellationToken = defa
304
279
public Task < Session > OpenSessionAsync ( SessionType type , CancellationToken cancellationToken = default )
305
280
{
306
281
cancellationToken . ThrowIfCancellationRequested ( ) ;
307
- switch ( type ) {
308
- case SessionType . User :
309
- return OpenSessionAsync ( Configuration . Sessions . Default , cancellationToken ) ;
310
- case SessionType . System :
311
- return OpenSessionAsync ( Configuration . Sessions . System , cancellationToken ) ;
312
- case SessionType . KeyGenerator :
313
- return OpenSessionAsync ( Configuration . Sessions . KeyGenerator , cancellationToken ) ;
314
- case SessionType . Service :
315
- return OpenSessionAsync ( Configuration . Sessions . Service , cancellationToken ) ;
316
- default :
317
- throw new ArgumentOutOfRangeException ( "type" ) ;
318
- }
282
+ return OpenSessionAsync ( GetSessionConfiguration ( type ) , cancellationToken ) ;
319
283
}
320
284
321
285
/// <summary>
@@ -348,9 +312,17 @@ public Task<Session> OpenSessionAsync(SessionConfiguration configuration, Cancel
348
312
}
349
313
}
350
314
315
+ internal SessionConfiguration GetSessionConfiguration ( SessionType type ) =>
316
+ type switch {
317
+ SessionType . User => Configuration . Sessions . Default ,
318
+ SessionType . System => Configuration . Sessions . System ,
319
+ SessionType . KeyGenerator => Configuration . Sessions . KeyGenerator ,
320
+ SessionType . Service => Configuration . Sessions . Service ,
321
+ _ => throw new ArgumentOutOfRangeException ( nameof ( type ) )
322
+ } ;
323
+
351
324
internal async Task < Session > OpenSessionInternalAsync ( SessionConfiguration configuration , StorageNode storageNode , SessionScope sessionScope , CancellationToken cancellationToken )
352
325
{
353
- ArgumentValidator . EnsureArgumentNotNull ( configuration , nameof ( configuration ) ) ;
354
326
configuration . Lock ( true ) ;
355
327
356
328
if ( isDebugEventLoggingEnabled ) {
0 commit comments