Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Sharing data between controllers #515


User avatar
0
joemo created

What is the correct way to share data from a service without re-retrieving the data each time?

For example, I have created a getCustomers service. But I want to use the data in both a header controller, and in the controller for a particular page.

At present this results in separate calls to the service each time - but I would like to just retrieve the data once and make it available globally.


1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    As you probably know, this is not a problem of ABP, and a general MVC question. But you may want to learn a good practice from us, so I will reply it :)

    You can use HttpContext.Items collection in a web request. You can add item to the collection and get later in same web request. So, it's like a per request cache.

    So, you check if item exists, get from db if not and fill it.