C# – Pattern for multiple datasources

cdesigndesign-patternsnetobject-oriented

I've already read this question on CodeReview. I was hoping for general advice.

I'm writing a service which will go to numerous data sources. Each source requires getting copious amounts of data and changing it to a single format. What is the best pattern for a task like this?

I currently have a "base" class which exposes a static GetData method, which the other classes inherit from and implement. This doesn't seem like the cleanest approach, so I was wondering what other approaches might suit my needs?

Best Answer

Sounds like you need a Repository pattern, maybe backed by a Strategy which would choose between different implementations.

How'd you actually do it is exposing a generic interface with your basic CRUD operations and make an implementation for each data source while letting the strategy pattern to decide on the implementation. If you're using dependency injection this might get a little tricky if deciding on which data source you're using is not easily deducted from the beginning.

Related Topic