@@ -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"/>.
@@ -277,11 +261,8 @@ internal Session OpenSessionInternal(SessionConfiguration configuration, Storage
277
261
/// }
278
262
/// </code></sample>
279
263
/// <seealso cref="Session"/>
280
- public Task < Session > OpenSessionAsync ( CancellationToken cancellationToken = default )
281
- {
282
- var configuration = Configuration . Sessions . Default ;
283
- return OpenSessionAsync ( configuration , cancellationToken ) ;
284
- }
264
+ public Task < Session > OpenSessionAsync ( CancellationToken cancellationToken = default ) =>
265
+ OpenSessionAsync ( Configuration . Sessions . Default , cancellationToken ) ;
285
266
286
267
/// <summary>
287
268
/// Opens new <see cref="Session"/> of specified <see cref="SessionType"/> asynchronously.
@@ -298,18 +279,7 @@ public Task<Session> OpenSessionAsync(CancellationToken cancellationToken = defa
298
279
public Task < Session > OpenSessionAsync ( SessionType type , CancellationToken cancellationToken = default )
299
280
{
300
281
cancellationToken . ThrowIfCancellationRequested ( ) ;
301
- switch ( type ) {
302
- case SessionType . User :
303
- return OpenSessionAsync ( Configuration . Sessions . Default , cancellationToken ) ;
304
- case SessionType . System :
305
- return OpenSessionAsync ( Configuration . Sessions . System , cancellationToken ) ;
306
- case SessionType . KeyGenerator :
307
- return OpenSessionAsync ( Configuration . Sessions . KeyGenerator , cancellationToken ) ;
308
- case SessionType . Service :
309
- return OpenSessionAsync ( Configuration . Sessions . Service , cancellationToken ) ;
310
- default :
311
- throw new ArgumentOutOfRangeException ( "type" ) ;
312
- }
282
+ return OpenSessionAsync ( GetSessionConfiguration ( type ) , cancellationToken ) ;
313
283
}
314
284
315
285
/// <summary>
@@ -342,6 +312,15 @@ public Task<Session> OpenSessionAsync(SessionConfiguration configuration, Cancel
342
312
}
343
313
}
344
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
+
345
324
internal async Task < Session > OpenSessionInternalAsync ( SessionConfiguration configuration , StorageNode storageNode , SessionScope sessionScope , CancellationToken cancellationToken )
346
325
{
347
326
configuration . Lock ( true ) ;
0 commit comments