Making singleton instances threadsafe

This commit is contained in:
Benjamin Russell
2016-07-25 12:15:03 -07:00
parent 31576d0731
commit 46032d3e2e
3 changed files with 16 additions and 36 deletions

View File

@@ -20,32 +20,23 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
/// <summary>
/// Main class for Language Service functionality
/// </summary>
public class LanguageService
public sealed class LanguageService
{
#region Singleton Instance Implementation
private static LanguageService instance;
private static readonly Lazy<LanguageService> instance = new Lazy<LanguageService>(() => new LanguageService());
public static LanguageService Instance
{
get
{
if (instance == null)
{
instance = new LanguageService();
}
return instance;
}
get { return instance.Value; }
}
/// <summary>
/// Default, parameterless contstructor.
/// TODO: Remove once the SqlToolsContext stuff is sorted out
/// Default, parameterless constructor.
/// </summary>
private LanguageService()
{
}
#endregion