I am looking for a design technique to achieve the following.
- two different data sources to read data
- I need to be able to dynamically add or remove more data sources
What I have done so far is, I have created the following :
IDataProvider
- StartReadData()
- EndReadData()
- List<DataObjs> (contains data)
XmlDataProvider : IDataProvider
CsvDataProvider : IDataProvider
IDataProviderManager
- List<IDataProvider> (has a collection of dataprovider)
DataProviderManager : IDataProvideManager
Now, I am looking for a better technique by which I can instantiate IDataProviders and manage it in a configurable way (add or remove more IDataProviders classes without doing any changes to code or recompiling).
Any nice design techniques or links to similar code are welcome.
Much Thanks.
Use the factory-pattern to abstract away the instantiation of the providers as a first step.
In that factory you can go either way with the implementation: config, reflection etc.
But my guess is that you will end up using an IoC-container in the long run as they are doing exactly what you want (and better)
Most containers can scan assemblies and import them transparent to your application without the need for recompiling.
I would suggest to invest a little time in getting to know DI instead of losing time on inventing your own solution. (which will be something to learn from too btw)
Using the factory allows you to change the implementation without breaking your application when you find the final solution that suits you.