0

Usually the Repository pattern looks like : enter image description here

What would be the best practice to make the repository handle more gateways (for Cache Redis, FTS/filtering Elasticsearch, Db Mysql etc.)

My ideas so far are to make a Repository array class that will loop through each repository when calling a method.

Also where would I implement the update/delete to remove from all the data sources?

6
  • Do you really have multiple data sources at runtime? Or do you just have multiple implementations where just one is used based on some configuration?
    – RubberDuck
    Commented Aug 7, 2016 at 0:13
  • yes you have more at runtime, you have a cache, a db and a filtering engine for now, and it might extend Commented Aug 7, 2016 at 12:04
  • or maybe I got it wrong, my task says : The DataRepository is responsible to talk to the different data sources, and for that reason it needs to be able to talk to a new data source with minimal additions to the code. It also needs to be able to select which data sources is going to communicate with (in other words, the data sources should be able to be added/removed dynamically). Commented Aug 7, 2016 at 12:06
  • Do you always need to check all of them, or do you check them in some order, only checking the next one if it wasn't already found?
    – RubberDuck
    Commented Aug 7, 2016 at 12:08
  • 1
    Then, for queries you want a Chain of Command. But since you need to act on all repositories on delete, you need to do as you said and try to update all datasources for updates. I'd wrap all your repositories in a facade repository to make sure they all get updated. Much like you mentioned. I think you're on the right track.
    – RubberDuck
    Commented Aug 7, 2016 at 12:19

1 Answer 1

1

Consider implementing special gateway implementation handling access to multiple other gateways (e.g. by looping as you wrote). It will be more clear and flexible like handling that inside repository. Such gateway can also hide cluster transparently.

3
  • So it would be like a super-Gateway? Commented Aug 11, 2016 at 8:32
  • But then the gateways would have to return data in the same way in order to be compatible with the same logic used to build your domain object (in the factory) Commented Aug 11, 2016 at 8:39
  • yes it should follow same object structure but i think it is advantage of that as at the end you need objects as from the other gateways. Commented Aug 15, 2016 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.