RSCG-Composite Provider – part 1 -idea
API Outage solved with local data
The problem that I try to solve is : How an UI can have data to show , even if the API from where it gathers data does not work ?
Imagine having a robust system that adaptively switches between retrieving data from multiple sources – including internal APIs, memory-based storage, or even JSON files near the UI. This flexibility makes all the difference when working with complex systems that may suddenly lose their external connectivity.
This could be solved with interfaces and a composite provider ( see http://msprogrammer.serviciipeweb.ro/2025/03/10/pattern-compositeprovider/ )
How It Works:
- You have an interface defining how your UI fetches data.Easy peasy!
- One implementation pulls data from the trusty API, ideally when it’s up and running smoothly.
- Another implementation acts as a backup hero, pulling data from a local JSON file or even hard-coded values.
And the best part? The composite provider handles switching between these sources seamlessly. No more coding headaches – it just works!
Making It Even Easier: Roslyn Code Generator to the Rescue
Tired of writing boilerplate code for this pattern every time? Please give a chance to a new Roslyn Code Generator (https://www.nuget.org/packages/RSCG_CompositeProvider). It automatically generates the composite providers you need, cutting down on repetitive work and letting you focus on what really matters – building awesome apps!
Leave a Reply