Skip to content

Conversation

bgrainger
Copy link
Member

Fixes #1508.

This differs from the existing StateChanged event in that:

  • it supports an async callback
  • it's only invoked when a connection is opened
  • it provides information about new vs existing and whether the connection was reset

Opening for API review. Needs tests before it can be merged.

This differs from the existing StateChanged event in that:

- it supports an async callback
- it's only invoked when a connection is opened
- it provides information about new vs existing and whether the connection was reset

Signed-off-by: Bradley Grainger <[email protected]>
@bgrainger bgrainger requested a review from ejball October 6, 2024 14:46
Signed-off-by: Bradley Grainger <[email protected]>
Signed-off-by: Bradley Grainger <[email protected]>
Signed-off-by: Bradley Grainger <[email protected]>
This will make it easier to add additional properties in the future if they're ever needed.

Signed-off-by: Bradley Grainger <[email protected]>
Rename type to 'Context'; this matches the existing UsePeriodicPasswordProvider.
Add CancellationToken; the user might execute commands against the server that might need to be cancelled.
Remove sync overload; it could be unnecessary.
Move types to their own files.
Allow multiple callbacks to be added.

Signed-off-by: Bradley Grainger <[email protected]>
Signed-off-by: Bradley Grainger <[email protected]>
@bgrainger bgrainger requested a review from ejball October 13, 2024 15:08
@bgrainger bgrainger marked this pull request as ready for review October 13, 2024 23:31
@bgrainger bgrainger merged commit b78e43f into master Oct 13, 2024
23 checks passed
@bgrainger bgrainger deleted the opened-callback branch October 13, 2024 23:32
@jnoordsij
Copy link
Contributor

Thanks for this! However I'm struggling to see how this should be used when creating a MySqlConnection, given that ConnectionOpenedCallback is internal?

@bgrainger
Copy link
Member Author

Documentation isn't fully updated yet, but you need to use MySqlDataSourceBuilder: https://mysqlconnector.net/api/mysqlconnector/mysqldatasourcebuilder/useconnectionopenedcallback/

DbDataSource is the .NET 7+ way of configuring DbConnection objects, and will be the preferred API for MySqlConnector going forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add (flexible) hook for initial connection opening event
3 participants