I have a function that sets 2 lists within a class to pull from a third party.
I put it in one function because going to the third party takes time and I only want to have to do it once for this page.
This is my class:
public class MyClass
{
public IEnumerable<dynamic> ListOne { get; set; }
public IEnumerable<dynamic> ListTwo { get; set; }
}
This is my function that sets & returns the lists
public MyClass GetLists()
{
//Here I have the code that connects to the third party etc
//Here set the items.. from the third party
MyClass _MyClass = new MyClass();
_MyClass.ListOne = ThirdParty.ListOne;
_MyClass.ListTwo = ThirdParty.ListTwo;
return (_MyClass);
};
}
So, now in my web API I have 2 functions - one that returns each list.
[Route("ListOne")]
public IHttpActionResult GetListOne()
{
IEnumerable<dynamic> ListOne = GetLists().ListOne;
return Json(ListOne);
}
[Route("ListTwo")]
public IHttpActionResult GetListTwo()
{
IEnumerable<dynamic> ListTwo = GetLists().ListTwo;
return Json(ListTwo);
}
My problem is that each time I call the webApi getListone or getListTwo, the function will run again and call the third party. How can I prevent this?
Thank you!