@@ -187,11 +187,8 @@ private void NotifyDisposing()
187187 /// }
188188 /// </code></sample>
189189 /// <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 ) ;
195192
196193 /// <summary>
197194 /// Opens new <see cref="Session"/> of specified <see cref="SessionType"/>.
@@ -205,21 +202,8 @@ public Session OpenSession()
205202 /// // work with persistent objects here.
206203 /// }
207204 /// </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 ) ) ;
223207
224208 /// <summary>
225209 /// Opens new <see cref="Session"/> with specified <see cref="SessionConfiguration"/>.
@@ -234,14 +218,8 @@ public Session OpenSession(SessionType type)
234218 /// }
235219 /// </code></sample>
236220 /// <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 ) ) ;
245223
246224 internal Session OpenSessionInternal ( SessionConfiguration configuration , StorageNode storageNode , bool activate )
247225 {
@@ -283,11 +261,8 @@ internal Session OpenSessionInternal(SessionConfiguration configuration, Storage
283261 /// }
284262 /// </code></sample>
285263 /// <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 ) ;
291266
292267 /// <summary>
293268 /// Opens new <see cref="Session"/> of specified <see cref="SessionType"/> asynchronously.
@@ -304,18 +279,7 @@ public Task<Session> OpenSessionAsync(CancellationToken cancellationToken = defa
304279 public Task < Session > OpenSessionAsync ( SessionType type , CancellationToken cancellationToken = default )
305280 {
306281 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 ) ;
319283 }
320284
321285 /// <summary>
@@ -348,9 +312,17 @@ public Task<Session> OpenSessionAsync(SessionConfiguration configuration, Cancel
348312 }
349313 }
350314
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+
351324 internal async Task < Session > OpenSessionInternalAsync ( SessionConfiguration configuration , StorageNode storageNode , SessionScope sessionScope , CancellationToken cancellationToken )
352325 {
353- ArgumentValidator . EnsureArgumentNotNull ( configuration , nameof ( configuration ) ) ;
354326 configuration . Lock ( true ) ;
355327
356328 if ( isDebugEventLoggingEnabled ) {
0 commit comments