clear singleton pattern concept please
I w开发者_如何学编程ant to make connection with sql server DB and maintain in singleton pattern. So is this functionality inbuilt in dot net ? or we mannually have to write the code for this scenario?
A lazy loaded singleton example
public sealed class Singleton
{ Singleton() { }
public static Singleton Instance
{
get
{
return Nested.instance;
}
}
class Nested
{
// Explicit static constructor to tell C# compiler
// not to mark type as beforefieldinit
static Nested()
{
}
internal static readonly Singleton instance = new Singleton();
}
}
Make use of sqlHelper
class will do work for you which is related to database connections
See here.
精彩评论