-
Notifications
You must be signed in to change notification settings - Fork 292
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 SqlDataSource #2119
Comments
Thanks @roji. We will discuss this internally and will get back to you. |
Yep, something like that. Npgsql has an NpgsqlDataSourceBuilder type for configuring an NpgsqlDataSource (when you're done you call Build() on it and get your data source); that would be the type of the NpgsqlDataSourceBuilder has all manner of configuration on it: stuff for managing access tokens, tweaking type mappings, logging and telemetry configuration, etc. Basically anything that you need to pre-configure for all the connections you'll be using from that data source. This is a much better alternative than static configuration, which is what you have to do if there's no data source and users are directly instantiating SqlConnections. (see the video I posted above for more discussion on how this is useful etc.) |
Note that as a first step, I'd just implement SqlDataSource so that users can use it as a simple connection factory (e.g. to be registered in DI). Adding actual support for e.g. access token management is additional work on top of that which would require a bit more refactoring inside SqlClient to support. |
Cool, I might look into that, since I already published a package which does that 😄 |
@roji I presume then something like ErikEJ.Data.SqlClient.DependencyInjection would be next (and maybe eventually Microsoft.Data.SqlClient.DependencyInjection) ? |
Yeah, exactly. SqlDataSource is something that needs to be implemented inside SqlClient (since ideally it would go on to support actual SqlClient-specific configurations like around access tokens). A DI integration package - similar to Npgsql.DependencyInjection - could be external (e.g. ErikEJ...), though ideally it would indeed be Microsoft.Data.SqlClient.DependencyInjection at some point. |
Once it gets implemented, AspNetCore.HealthChecks.SqlServer (a very popular health check package for SQL Server with 37 milion downloads) should start using it too. I've created Xabaril/AspNetCore.Diagnostics.HealthChecks#2123 to track it. |
.NET 7.0 introduced the new DbDataSource abstraction to System.Data (issue), here's a video discussing it in depth.
Now, the .NET 7.0 implementation provides a default implementation which can be obtained from the ADO.NET provider's DbProviderFactory without the driver needing to implement anything. So the following code already works today:
However, this provides a database-agnostic DbDataSource which isn't typed to any specific provider, so it hands out DbConnections rather than SqlConnections, which may be cumbersome to work with if the user is only targeting SQL Server.
A proper SqlDataSource implementation in SqlClient would solve this, and also provide a good configuration/setup point (e.g. for authentication/access tokens, rather than the current static methods).
The text was updated successfully, but these errors were encountered: