If we have a singleton class like LoadBalancer and need one instance per ASP.NET application, then where to store it ?
Currently I use Application.Add("LoadBalancer", LoadBalancer.Instance) in Application_Start() in Global.asax.
Also Application object is created by ASP.NET and there are multiple instances per application based on workload. Also I can declare a static instance of my LoadBalancer in Global.asax.
Which is preferred ? Any better idea ?
If it is a Singleton why do you want to store in Application items? Isn’t it supposed to return the same instance when you use LoadBalancer.Instance from anywhere in the application?
In case your site is using load balancing or is ina web farm each server would have its instance of Application object and LoadBalancer.Instance.