I'm trying to migrate a small .net framework project to .net core one. But I've spent a couple of hours searching how to adopt the code below to .net core 2.0. But I was unlucky, because it seems that System.Data.Common functionality was cut for some reason. So, I've 2 problems here:
How can we get a factory base only on provider name string? Any other thought how to perform loosely coupled db connection factory
public class ConnectionFactory
{
protected readonly DbProviderFactory Factory;
protected readonly string ConnectionString;
public ConnectionFactory(string connectionStringName)
{
var settings = ConfigurationManager.ConnectionStrings[connectionStringName];
this.Factory = DbProviderFactories.GetFactory(settings.ProviderName);
this.ConnectionString = settings.ConnectionString;
}
public DbConnection Connection
{
get
{
var con = Factory.CreateConnection();
con.ConnectionString = this.ConnectionString;
return con;
}
}
}
DbProviderFactories will be available in .net core 2.1 (2Q 2018).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With