Wednesday, 28 August 2013

Singleton implementation check

Singleton implementation check

Hi I am interested in implementing a method that returns an singleton
object.I have created an implementation based on an example found on MSDN
but I am not really sure if my implementation is corect.
The code runs just fine but I am not sure how to check if it's the same
object instance.
Here is my code:
public class FileShareAccessFactory : IFileShareAccessFactory
{
private volatile static IFileShareAccess m_fileShareAccess;
private static object m_SyncRoot = new object();
public IFileShareAccess GetFileShareAccessInstance(IContextFactory
contextFactory, ILogger logger)
{
if (m_fileShareAccess == null)
{
lock (m_SyncRoot)
{
if (m_fileShareAccess == null)
{
m_fileShareAccess = new
FileShareAccess(contextFactory, logger);
}
}
}
return m_fileShareAccess;
}
}

No comments:

Post a Comment