My MVC application currently uses the Global.asax
, Application_Start
method to load tons of data, and then exposes it as collections. For example:
Current Usage Example:
// Global.asax
public static DataRepository Repository { get; set; }
protected void Application_Start()
{
// All the normal stuff...
// Preload this repository.
DataRepository = new DataRepository();
}
// HomeController.cs Example
public ActionResult Index(){
return Json(MyApplication.Repository.GetSomeCollection(),
JsonRequestBehavior.AllowGet);
}
What I'm trying to do:
I want to use the ASP.Net 4.0 + IIS 7.5 Application Preload functionality, but need to expose the repository to the rest of the application. Something like:
// pseudo code attempt at goal
public class ApplicationPreload : IProcessHostPreloadClient
{
public MyRepositoryClass Repository { get; set; }
public void Preload(string[] parameters)
{
// repository class's constructor talks to DB and does other crap.
Repository = new MyRepositoryClass();
}
}
Question
How can I expose a repository class or even a simple IEnumerable<T>
collection using the Preload()
method implemented via IProcessHostPreloadClient
?