Reputation: 319
I've been reading about patterns and i am trying to implement the Singleton
Is my implementation correct? How can i Improve it? There are so many implementation on the web............
public sealed class SingletonProxy
{
private static IInfusion instance;
static SingletonProxy() { }
SingletonProxy() { }
public static IInfusion Instance
{
get
{
if(instance == null)
{
instance = XmlRpcProxyGen.Create<IInfusion>();
}
return instance;
}
}
}
Upvotes: 0
Views: 270
Reputation: 26792
Since we now have the System.Lazy class, I tend to use this implementation:
public sealed class SingletonProxy
{
private static readonly Lazy<IInfusion> instance
= new Lazy<IInfusion>(XmlRpcProxyGen.Create<IInfusion>);
public static IInfusion Instance
{
get { return instance.Value; }
}
}
Upvotes: 1