There seem to be three different methods for storing a variable that will be available for every request in the application:
Global.asax.cs
public class MvcApplication : HttpApplication
{
protected void Application_Start()
{
Application["SiteDatabase"] = new SiteDatabase();
}
}
Owin:
public partial class Startup
{
public void ConfigureAuthentication(IAppBuilder Application)
{
Application.CreatePerOwinContext<SiteDatabase>(new SiteDatabase());
}
}
Static container
public static class GlobalVariables
{
private SiteDatabase _Database;
public SiteDatabase Database
{
get { return _Database ?? new SiteDatabase(); }
}
}
What are the relative advantages of each method?
source
share