H
Hornet77
Hi
I need to call a wide variety of methods to query the database in each
of my aspx pages; to achieve this target I wrote a "DbManager" class
with a private static instance and a set of static method to call from
my pages:
public class DbManager
{
private static DbManager instance = null;
public static bool MethodA()
{
checkInstance();
return instance.methodA();
}
private static void checkInstance()
{
if (instance == null)
{
instance = new DbManager();
}
}
private bool methodA()
{
//query database
return true;
}
}
in my generic aspx page where I need to query the database I simply wrote:
bool result = DbManager.MethodA();
With this structure I was convinced to have a global instance of
DbManager, created once at application start and never disposed; running
the app, however, I've noticed that the instance need to be re-created
every time I try to call its methods (it appears null and in
checkInstance() it is created new)..... why? is not the "static"
attribute enough to have a single instance of my DbManager class? I need
to add it to Application[] and istantiate it in the start event of
Global.asax?
Thanks in advance for your response
I need to call a wide variety of methods to query the database in each
of my aspx pages; to achieve this target I wrote a "DbManager" class
with a private static instance and a set of static method to call from
my pages:
public class DbManager
{
private static DbManager instance = null;
public static bool MethodA()
{
checkInstance();
return instance.methodA();
}
private static void checkInstance()
{
if (instance == null)
{
instance = new DbManager();
}
}
private bool methodA()
{
//query database
return true;
}
}
in my generic aspx page where I need to query the database I simply wrote:
bool result = DbManager.MethodA();
With this structure I was convinced to have a global instance of
DbManager, created once at application start and never disposed; running
the app, however, I've noticed that the instance need to be re-created
every time I try to call its methods (it appears null and in
checkInstance() it is created new)..... why? is not the "static"
attribute enough to have a single instance of my DbManager class? I need
to add it to Application[] and istantiate it in the start event of
Global.asax?
Thanks in advance for your response