Jacob Mason
Jacob Mason

Reputation: 1395

Design patterns for applications with multiple data sources?

I'm currently working on windows form application that needs to operate both offline and online. The idea is that when the device running the application has an internet connection it will fetch from a web service to get its data, however when there is no connection it fetches from a local data source in the form of JSON in the local file system.

I would preferably like to use the Service and Manager design pattern (3-tier). However I am unsure which to give the responsibility to of deciding on the data source to use. Should the managers have access to two different services and each service looks at a different source and understands how to interact with each, or should the services be aware of how to interact with both data sources?

Upvotes: 0

Views: 1565

Answers (1)

Gal Ben Arieh
Gal Ben Arieh

Reputation: 422

I would suggest to use the 3 tier pattern with an IoC container, that way you can inject the right DAL Object as the data source of the app, according to the state of the application - In case it's online, inject an "OnlineDAL" which inherits from IDAL interface, otherwise, inject "OfflineDAL" which also inherits from IDAL interface.

Remember to change the injected class whenever the app goes on/off (with an event listener or something)

Upvotes: 1

Related Questions