extend session events to cover raw connections and commands - #493
Merged
Conversation
botinko
reviewed
Jul 31, 2026
The ORM's own DbCommandExecuting/Executed events only fire for commands run through its own execution path, and there was no hook for a connection's first genuine open or for a raw connection handed out without a DbCommand. Code using DirectSqlAccessor, or needing the raw connection directly, had no way to observe any of this. Adds a DbConnectionOpened event fired on the Closed to Open transition, an EventNotifyingDbCommand wrapper so DirectSqlAccessor.CreateCommand() raises the same execute events ORM commands do, and an async GetConnectionAsync with an awaitable raw-connection-accessed hook so callers that need the connection itself can hook in without blocking a thread.
botinko
reviewed
Jul 31, 2026
| /// <summary> | ||
| /// Event args for <see cref="SessionEventAccessor.DbConnectionOpened"/>. | ||
| /// </summary> | ||
| public readonly struct DbConnectionEventArgs |
Collaborator
There was a problem hiding this comment.
Make it readonly record struct for simplified syntax
|
|
||
| public override ValueTask DisposeAsync() => innerCommand.DisposeAsync(); | ||
|
|
||
| public EventNotifyingDbCommand(Session session, DbCommand innerCommand) |
Collaborator
There was a problem hiding this comment.
Use Primary Constructor syntax for new classes
|
|
||
| using System; | ||
| using System.Data.Common; | ||
| using System.Threading; |
Collaborator
There was a problem hiding this comment.
Remove these usings
They are added by default
SergeiPavlov
approved these changes
Jul 31, 2026
SergeiPavlov
reviewed
Aug 1, 2026
| using (var session = Domain.OpenSession()) | ||
| using (var transaction = session.OpenTransaction()) { | ||
| var callOrder = new System.Collections.Generic.List<int>(); | ||
| var callOrder = new List<int>(); |
Collaborator
There was a problem hiding this comment.
Suggested change
| var callOrder = new List<int>(); | |
| List<int> callOrder = []; |
botinko
self-requested a review
August 4, 2026 20:46
Collaborator
Author
|
changes waiting on rules: https://github.com/servicetitan/stcrm-ops/rules?ref=refs%2Fheads%2Frunbook-guide |
botinko
approved these changes
Aug 4, 2026
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DbConnectionOpenedevent onSessionEventAccessor, fired once per genuine Closed→Open connection transitionEventNotifyingDbCommandwrapper soDirectSqlAccessor.CreateCommand()raises the sameDbCommandExecuting/DbCommandExecutedevents the ORM's own commands doGetConnectionAsynconIDirectSqlService/DirectSqlAccessor, backed by the existing async prepare path, plus an awaitable raw-connection-accessed hookRelated:
Test plan
dotnet buildonXtensive.OrmandXtensive.Orm.TestsDbConnectionOpenedEventTest,EventNotifyingDbCommandTest,DirectSqlGetConnectionAsyncTest) pass against a local SQL Server containerXtensive.Orm.Tests.Storagesuite run before/after: identical pre-existing failures, no regressions