Putting aside, for now, the arguments about the relative virtues and disvirtues of the Singleton pattern, and considering that a Singleton is typically considered to be an instance that persists for the lifetime of an application, what would be the best way to go about having a Singleton that has a limited life?
Is there anything amiss with something like the following:
public class CategoryHandler
{
private static DateTime m_expires;
public bool HasExpired
{
get return DateTime.Now > m_expires;
}
private CategoryHandler()
{
m_expires = DateTime.Now.AddMinutes(60);
}
public static CategoryHandler Instance()
{
if(HasExpired)
{
//Dispose and reconstruct
}
else
{
//Use existing instance
}
}
}
Or is there a much better way of approaching this problem?