question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MySql5Processor does not allow to provide custom IDbFactory

See original GitHub issue

The 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:open
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rhegnercommented, Oct 10, 2018

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 if MySql.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.

0reactions
fubar-codercommented, Oct 10, 2018

That’ll work. 4.0 will contain some big changes, but this version will take some time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IDBFactory - Web APIs - MDN Web Docs
Chrome Edge IDBFactory Full support. Chrome24. more. Toggle history Full support. Edge12. Toggle hist... cmp Full support. Chrome23. Toggle history Full support. Edge12. Toggle hist... databases...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found