Dependency Injection - Data Exporter
I’ve been trying to wrap my head around dependency injection, but I’m struggling to bridge the gap between written explanations and putting the paradigm into practice within my own code.
I need to export data from an Access database to an Excel spreadsheet using Interop (the OLE DB driver isn't an option here, unfortunately), but the goal is to eventually get the data out of Access and into a better format like perhaps a SQL Server database.
To make the code more flexible for these changes in the future, I tried to implement a general IExporter interface that could take any kind of input and export the data to any kind of output.
Would anyone be able to offer any feedback on how I could improve the below? It feels like my implementation is a bit off design-wise.
IDataExporter.cs:
DataExporter.cs:
2 Replies
AccessDataExporter.cs:
Implementation:
to have a more loose coupling i would actually recommend a data reader, an data writer and then a service that takes both to do the actual job:
this way u could do something like
basically u have separated the reading and the writing, thus u need to write every reading/writing type just once and can wire it together.
with ur example implementation u would have a tight coupling, as in if u want an JSON to MYSQL and a JSON to Access exporter, u would have to implement the JSON part twice
ofc this is just a small example, i would also give the data source/data destination info on the actual method
eg
and similar for the writer