I’ve been reading a bit on the singleton concept. While not fully understanding it, I’d like to have my instance getter in my base class.
For example, my class base class RepositoryBase will have the following method:
private static RepositoryBase _instance;
public static RepositoryBase Instance
{
get
{
if (_instance == null)
_instance = new RepositoryBase();
return _instance;
}
}
Does this actually make sense? I believe that when a new child class (take for example UserRepository) inherits RepositoryBase, what it is still getting when retrieving Instance is an instance of the general class RepositoryBase and not an instance of UserRepository.
Is there any way I can make it such that Instance automatically returns the child class, while still remaining in the base class? Thanks!
You could try with a generic base class
Then use it like this