MySql5Processor does not allow to provide custom IDbFactory
See original GitHub issueThe constructor of MySql5Processor
requests a concrete instance of MySqlDbFactory
from DI. This makes it hard to provide a custom DbFactory. It forces me to derive my custom DbFactory from MySqlDbFactory
, which I don’t want.
I suggest that the constructor of MySql5Processor
should request a more generic type (ideally this would be IDbFactory
or some other pure interface - DbFactoryBase
would also be acceptable). This would allow me to provide an implementation which is not derived from MySqlDbFactory
or ReflectionBasedDbFactory
.
Background: In my project I’d like to use MySqlConnector
instead of MySql.Data
. My current workaround is to derive from MySqlDbFactory
private class MySqlConnectorDbFactory : MySqlDbFactory
{
public MySqlConnectorDbFactory(IServiceProvider serviceProvider)
: base(serviceProvider)
{ }
protected override DbProviderFactory CreateFactory()
=> MySqlClientFactory.Instance;
}
and then to configure the builder like this:
builder.Services.AddScoped<MySqlDbFactory, MySqlConnectorDbFactory>();
builder.AddMySql5();
But I don’t think this is a particularly nice solution.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Ok I see. Would introducing a new
IMySqlDbFactory
solve the problem?A very different approach would be to support MySqlConnector out of the box in
ReflectionBasedDbFactory
(as a fallback ifMySql.Data
is not available). That would be convenient for me, but I still think it would be advantageous to have a cleaner way for providing a custom factory.That’ll work. 4.0 will contain some big changes, but this version will take some time.