Is it possible to nest a singleton class inside a non-singleton class in C#, and if so, are there any restrictions to the life-cycle of the singleton in this case?
public class NonSingletonClass
{
public NonSingletonClass()
{
// Initialize some stuff.
}
// Put some methods here.
public class SingletonClass
{
// Singleton construction goes here.
// Put some methods here.
}
}
In the design of my application, this makes sense, but I need to know of any potential gotchas before I actually implement this.
EDIT: Specifically, I have a job host that executes tasks based on a timer. The NonSingletonClass
in this case is an instantiation of a task. The SingletonClass
is a repository of data that is used by NonSingletonClass
, but can be modified from outside of NonSingletonClass
. SingletonClass
exists to ensure that even if there are multiple NonSingletonClass
instances, there will still be only one set of instructions and data for all of them.