Skip to content

Commit db0bf1f

Browse files
committed
Refactoring: simplify OpenSessionAsync() code
1 parent c17c922 commit db0bf1f

File tree

2 files changed

+4
-24
lines changed

2 files changed

+4
-24
lines changed

Orm/Xtensive.Orm/Orm/Domain.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -315,18 +315,8 @@ public Task<Session> OpenSessionAsync(SessionType type, CancellationToken cancel
315315
public Task<Session> OpenSessionAsync(SessionConfiguration configuration, CancellationToken cancellationToken = default)
316316
{
317317
ArgumentNullException.ThrowIfNull(configuration);
318-
319-
SessionScope sessionScope = null;
320-
try {
321-
if (configuration.Supports(SessionOptions.AutoActivation)) {
322-
sessionScope = new SessionScope();
323-
}
324-
return OpenSessionInternalAsync(configuration, null, sessionScope, cancellationToken);
325-
}
326-
catch {
327-
sessionScope?.Dispose();
328-
throw;
329-
}
318+
using SessionScope sessionScope = configuration.Supports(SessionOptions.AutoActivation) ? new() : null;
319+
return OpenSessionInternalAsync(configuration, null, sessionScope, cancellationToken);
330320
}
331321

332322
internal SessionConfiguration GetSessionConfiguration(SessionType type) =>

Orm/Xtensive.Orm/Orm/StorageNode.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,8 @@ public Task<Session> OpenSessionAsync(SessionType type, CancellationToken cancel
8282
public Task<Session> OpenSessionAsync(SessionConfiguration configuration, CancellationToken cancellationToken = default)
8383
{
8484
ArgumentNullException.ThrowIfNull(configuration);
85-
86-
SessionScope sessionScope = null;
87-
try {
88-
if (configuration.Supports(SessionOptions.AutoActivation)) {
89-
sessionScope = new SessionScope();
90-
}
91-
return domain.OpenSessionInternalAsync(configuration, this, sessionScope, cancellationToken);
92-
}
93-
catch {
94-
sessionScope?.Dispose();
95-
throw;
96-
}
85+
using SessionScope sessionScope = configuration.Supports(SessionOptions.AutoActivation) ? new() : null;
86+
return domain.OpenSessionInternalAsync(configuration, this, sessionScope, cancellationToken);
9787
}
9888

9989
public void ClearSequenceCaches()

0 commit comments

Comments
 (0)