Frage

I have APIs from around 6 providers. I also have a database where I disable or enable the providers I want to use.

I have an ASP.NET MVC4 application. In this I want to be able to use multiple provider's APIs and display data. Each provider's API send a response in a different format - it could be JSON for one and XML for another.

Now I am stuck because:

  1. Each API needs its own code to be parsed. Where does this provider-specific code go into? A single class where for each provider a specific method does the parsing? Or do I create a new class for each provider and do the parsing there?

  2. How can I efficiently call a particular provider's method? Is some bit of hardcoding essential in the sense that if the Provider name is "Prov A" then I call the method GetProvAData?

I hope I have explained the issue clearly enough. Any help will be welcome. Thanks in advance.

Regards,

Satish

War es hilfreich?

Lösung

This really has nothing to do with MVC, it's a basic software development pattern problem.

Assuming your data from various providers all has to end up in the same format, then this is a textboox example of the Strategy pattern. You would basically create multiple provider parsers that all have the same interface, and you just call Execute or Parse or whatever you want to call it on all of them.

If what you do with the data is different for different providers, then it's a bit more complex because you now have to modify your app to support the individual providers data, and without knowing exactly what that is we can't really give you advice on how to do it.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top