Reflection v Dependency Injection / IOC - real example...

Zeppedy

New member
Joined
Jan 28, 2019
Messages
1
Programming Experience
10+
Hi

I'm relatively new to C# and particularly OOO coding. I understand the concepts but struggle to see how I can apply them. I have something to work on now that might help with that.

I'll be polling a directory where random files will be produced, the file naming convention will allow me identify which client it is i.e. clienta_yyyymmdd_hhmmss.txt or something similar. Each client will have a completely bespoke format. More clients will be added over time. I will just be reading the files, transforming to a consistent format and pushing this to another source. So I'm looking at the best way to approach this, the goal being scalability so that new client formats can be supported as simply as possible. With my limited knowledge I was thinking maybe:-

a) A config file matching a client to an assembly (all clients would have the same entry method) and use reflection to invoke the transform method on the relevant assembly. My thinking is I can then just drop in a client specific DLL and tweak the config to add new clients.
b) Would this problem be a candidate for taking a DI / IOC approach, albeit I'll need to understand how!

Any thoughts or suggestions welcome, I'm viewing this as a great opportunity to implement a real solution. Cheers
 
One option here might be to use a plugin-style approach. You could define an interface with the appropriate methods and you can then write code against that interface. You could even create an abstract class if part of the functionality was going to be common to all implementation and then write against that class. You could then create a DLL for each client that included a class that implemented that interface or inherited that class and then provided the client-specific functionality in overridden members. You could then load the appropriate assembly via Reflection by using a similar naming convention to your data files.
 
Back
Top Bottom