I have a Class which i chose to implement like attached in my Winforms Application.
This works very and gives a great performance.
The problem now however is that we are building an ASP.NET application where i would like to reuse this code.
However the web application could be accessing different Data on each request, meaning the data stored in this Singleton would be invalid and the correct data should be loaded.
How can i implement this in a way where i get the performance from using singleton in my Windows Application but on my Web application i would like nothing to be stored for more than the current request
The Idea behind doing this is to enable very fast lazy loading on objects refering to these ShiftGroups.
Should i do this in some other way ?
public class ShiftGroups
static BindingList<ShiftGroup> m_loaded_groups;
public static BindingList<ShiftGroup> GetShiftGroups()
if (m_loaded_groups == null)
public static ShiftGroup GetShiftGroup(int groupID)
return GetShiftGroups().Where(mGroup => mGroup.ID == groupID).FirstOrDefault();
private static void LoadGroups()
m_loaded_groups = new BindingList<ShiftGroup>();
using (SqlConnection cnx = Data.Connection)
using (SqlCommand command = new SqlCommand("SELECT * FROM vagtgruppe_db;", cnx))
SqlDataReader reader = command.ExecuteReader();
int id = (int)reader["vagtgruppe_id"];
string name = (string)reader["vagtgruppe_navn"];
int area = (int)reader["vagtgruppe_area"];
int order = (int)reader["vagtgruppe_order"];
bool doPrint = ((int)reader["vagtgruppe_print"]) == 1;
ShiftGroup mGroup = new ShiftGroup(name, area, id, order, doPrint);