Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Command and Exception Interceptors #420

Closed
bgrainger opened this issue Jan 3, 2018 · 4 comments
Closed

Implement Command and Exception Interceptors #420

bgrainger opened this issue Jan 3, 2018 · 4 comments
Labels

Comments

@bgrainger
Copy link
Member

https://dev.mysql.com/doc/connector-net/en/connector-net-interceptors.html

The BaseCommandInterceptor lets you perform additional operations when a program issues a SQL command.

It's configured by the connection string and loaded (via reflection) at runtime.

@bgrainger bgrainger changed the title Implement CommandInterceptors Implement Command and Exception Interceptors Jan 3, 2018
@bgrainger
Copy link
Member Author

Command Interceptors

The existing API is not compatible with async command execution (a big selling point of this library). Although it could be changed to be so, that would introduce significant additional complexity.

It's likely that supporting these would require code refactoring that would hurt performance (e.g., removing ValueTask) for all users, not just users who actually add a command interceptor at runtime.

It's also not clear to me what a compelling use case for these interceptors is; moreover, they can easily be implemented via the "Decorator" pattern (e.g., this is how Dapper works).

I tried to search GitHub for uses of command interceptors but only found copies of Connector/NET source code itself (not clients defining derived types).

Exception Interceptors

Many of the same arguments apply. It's also possible to wrap exceptions (or suppress them, which isn't possible with MySQL's exception interceptors) via the decorator pattern.

@mguinness
Copy link
Contributor

I'd raised this previously in #140. This would be analogous to IDbCommandInterceptor in EF 6, but isn't yet supported in EF Core - tracked in Lifecycle hooks but yet to be implemented.

In terms of use cases it could be useful to define session variables like SET time_zone = '+00:00'; as there's no other way to achieve this in Entity Framework without command interception.

@bgrainger
Copy link
Member Author

I'd raised this previously in #140.

Hmm, I must have forgotten about that when I created this issue; sorry.

In terms of use cases it could be useful to define session variables like SET time_zone = '+00:00';

Does the suggestion at #519 (comment) solve this use case? (Assuming you can use the underlying ADO.NET library and attach that event handler when using EF.)

@mguinness
Copy link
Contributor

I'd forgotten about that workaround, but that should do the trick.

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

No branches or pull requests

2 participants