I am trying to create a .Net core console application with can use different database connections. currently, i am writing the application to use SQL and in future if i want to use Oracle or any other connection then i should be able to easily achieve this. So, i am using dependency injection for this purpose.
I am exploring the below option using ServiceCollection
IConfiguration config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", true, true)
.Build();
var sqlconnectionstring = config.GetConnectionString("SQLConnectionString");
var serviceProvider = new ServiceCollection()
.AddLogging()
.AddSingleton<IChannel, Email>()
.AddTransient<IDBObjectManager>(s => new SQLDBObject(sqlconnectionstring))
Here the idea is, I have created a SQLDBObject class which will have SQL related functionalities. In future, I will create one for some other db.
I am seeing many articles around this with Entity Framework but at this point I am checking to make this functionality work with my SQL connection class.
I don't know if i am using the DI correctly here. Can someone advise?