Skip to content

Commit

Permalink
Added singleton class; lazily instantiated
Browse files Browse the repository at this point in the history
  • Loading branch information
safalin1 committed Jun 2, 2019
1 parent ceb6869 commit 511247b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Chiaki/Singleton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;

namespace Chiaki
{
/// <summary>
/// Represents a singleton instance of a class
/// </summary>
/// <typeparam name="T">Type of the singleton</typeparam>
public class Singleton<T> where T : new()
{
private static readonly Lazy<T> _instance = new Lazy<T>(() => new T());

/// <summary>
/// Gets a singleton instance of <typeparamref name="T"/>
/// </summary>
public static T Instance => _instance.Value;
}
}

0 comments on commit 511247b

Please sign in to comment.