In the below code i want the "GetClassTeacher" method to be executed only once per session in Asp.net application, I have used session to check whether the object is null before calling the database.
My question is, Is this the best way to implement this method or can i use singleton pattern to accomplish this, If so how to implement it per session.
public class School
{
public List<Student> GetAllStudents() {}
public List<Teacher> GetAllTeachers() {}
//Singleton pattern or Check for Null
public Teacher GetClassTeacher()
{
Teacher teacher = new Teacher();
teacher = Session["Teacher"] as Teacher
if (teacher == null)
{
//Get Teacher Info from Database
}
}
}