I would use the Singleton template to store your "application wide" variable. It is static, will be allocated after the first use and is available for the duration of your application. I also think this is much better than using an untyped HashTable application such as an application. For me, Application storage is a relic from ASP and is no longer useful in an object-oriented world.
Be careful that a static variable is initialized only once, because each request for a web request / service is executed in its own thread.
Similarly, you can load data the first time you use it and access it everywhere with MyData.Data:
public class MyData { private static IList<MyData> _data { get; set; } public static IList<MyData> Data { get { if (_data == null) _data = load Big data struct from DB. return _data; } } }
An event would be better initialization in a static constructor, because then the call would be thread safe.
slfan source share