I have created an singleton class, this class returns a database connection. So my question is this connection is also satisfying singleton criteria?
If no, than how I can make it singleton.
Here is the code.
public sealed class SingletonDB
{
static readonly SingletonDB instance = new SingletonDB();
static SqlConnection con =new SqlConnection(ConfigurationManager.ConnectionStrings["mydb"].ConnectionString);
// Explicit static constructor to tell C# compiler
// not to mark type as beforefieldinit
static SingletonDB()
{
}
SingletonDB()
{
}
public static SingletonDB Instance
{
get
{
return instance;
}
}
public static SqlConnection GetDBConnection()
{
return con;
}
}