-
Notifications
You must be signed in to change notification settings - Fork 390
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
Pass loggerFactory into MySqlConnection #1813
Conversation
@trejjam this is the wrong approach; it looks like it creates a MySqlDataSource instance for each and every instance of MySqlRelationalConnection; MySqlDataSource typically represents a connection pool and should be shared. In general, an EF provider (e.g. the Pomelo provider) should not be concerned with configuring the lower-level ADO.NET provider (in this case the MySqlConnector). @lauxjpn I really hope to get to building DbDataSource support into EF itself for 9.0; I've added DbDataSource specifically to EFCore.PG in the meantime, so you could copy that, but ideally this would all be managed in the core. |
I was not aware of
|
One potential issue with this is that it looks like Pomelo sometimes (or always? I haven't fully followed the code path) adds options to the connection string: Pomelo.EntityFrameworkCore.MySql/src/EFCore.MySql/Storage/Internal/MySqlRelationalConnection.cs Line 75 in 0209341
This wouldn't be possible when using a |
It could be done if new ServiceDescriptor(
typeof(MySqlDataSource),
serviceProvider =>
{
var dataSourceBuilder = new MySqlDataSourceBuilder(
serviceProvider.GetService<IOptions<MySqlConnectionStringBuilder>>().Value.ConnectionString
).UseLoggerFactory(serviceProvider.GetService<ILoggerFactory>());
dataSourceBuilderAction?.Invoke(dataSourceBuilder);
return dataSourceBuilder.Build();
},
dataSourceLifetime)); EF then can do: serviceCollection.AddOptions<MySqlConnectionStringBuilder>()
.Configure<IOptions<PomeloEfCoreOptions>>((pomeloOptions, mysqlOptions) => mysqlOptions.TreatTinyAsBoolean = pomeloOptions.TreatTinyAsBoolean);
serviceCollection.AddSingleton<IValidateOptions<MySqlConnectionStringBuilder>, EfCoreMysqlValidation>();
public class EfCoreMysqlValidation : IValidateOptions<MySqlDataSourceOptions>
{
public EfCoreMysqlValidation (IOptions<PomeloEfCoreOptions> pomeloEfCoreOptions) {
_pomeloEfCoreOptions = pomeloEfCoreOptions;
}
public ValidateOptionsResult Validate(string? name, MySqlConnectionStringBuilder options)
{
// validate options.TreatTinyAsBoolean == _pomeloEfCoreOptions.Value.TreatTinyAsBoolean
}
} |
By that EF can set and also verify configuration (so a user does not shoot himself in the leg) and heavy lifting is done in the |
@roji Thanks, I'll take a look at it. |
Closing in favor of #1817 |
Hi, I am not completely sure this is how it should be implemented - speaking about passing ILoggerFactory. But I would love to have a native way to attach the logger pipeline into mysqlConnector.
I would be glad to receive any guidance on how to make this or similar things accepted