I currently have the call to my file io class in the constructor of my controller class of my project. I noticed the csv file gets re-read every time I hit the api endpoint, which is not ideal. Where should I have this so my csv only gets read in on startup?
namespace API.Controllers
{
[ApiController]
public class CovidDataController : ControllerBase
{
private ReadCSV readCSV;
public CovidDataController()
{
readCSV = new ReadCSV("CovidFileIO/covid19-download.csv");
readCSV.CreateDataObjects(100); // Pass in how many lines to read
}
// This endpoint will return records from the covid data object.
[Route("api/[controller]")] // route is api/CovidData
[HttpGet]
public List<CovidData> GetData()
{
return readCSV.covidDataObjects;
}
}
}