I’m looking for a best practice in Ionic 2 for following pattern:
I have a provider (interface, REST implementation and MOCK implementation available). Provider is registered using a string-name and REST/MOCK provider is swapped centrally.
Any component/service gets the provider injected by @Inject(‘ProviderName’). So far so good.
Now I have some providers which shall be cached for specific amounts of time. Since I want it to be testable, the provider shall either use the REST or MOCK provider internally, according to what is registered.
But I also want to be able to swap the cached provider with the REST/MOCK provider directly and omit caching.
How would you ideally do this?
My idea so far:
Register a ‘CachedProviderName’ using the same interface as ‘ProviderName’. Internally it gets ‘ProviderName’ injected and uses it. Other components use ‘CachedProviderName’. However, I would still be able to switch between cached and rest/mock provider centrally by just registering it as ‘CachedProviderName’.
Are there better solutions?