This project is read-only.

More widgets with one data source on one page

Topics: Core, Writing modules
Oct 17, 2013 at 3:36 PM
I'm trying to write a module with several widgets usable in one page with a single source of data. For example, the detail page of product of e-shop. On this page two widgets, one for description of product and one for a photo gallery of the product. The data source is the external API. The aim is to be performed only one query to API for both widgets. What is good practice to do? I thought retrieve data from API at capturing request and then both widgets have get data from some object of Request. Exists any example? Thanks a lot for response.
Oct 17, 2013 at 4:51 PM
You can implement a service that calls the external API and cache the results, serve from cache when another call is made, inject the service in both widget parts' drivers or handlers.

There are several options for caching.

If you want to use per-request session objects instead of caching, you can get to it using IHttpContextAccessor

instead of Session, you can use Items property.

Just ideas, I'm not sure if these would work, or good practice.