daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Jan 16th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public sealed class DocumentClientSingleton
  2. {
  3.     public static IDocumentClient GetInstance()
  4.     {
  5.         return _lazy.Value;
  6.     }
  7.  
  8.     /// <summary>
  9.     /// Only use this for testing!
  10.     /// </summary>
  11.     /// <returns></returns>
  12.     public static IDocumentClient SetInstanceForTesting(IDocumentClient client)
  13.     {
  14.         _lazy = new Lazy<IDocumentClient>(() => client );
  15.         return _lazy.Value;
  16.     }
  17.  
  18.     private static  Lazy<IDocumentClient> _lazy =
  19.         new Lazy<IDocumentClient>(InstantiateDocument);
  20.  
  21.     private static IDocumentClient InstantiateDocument()
  22.     {
  23.         return new DocumentClient(
  24.             new Uri(ConfigurationManager.AppSettings["endpoint"]),
  25.             ConfigurationManager.AppSettings["authKey"],
  26.             new ConnectionPolicy
  27.             {
  28.                 ConnectionMode = ConnectionMode.Direct,
  29.                 ConnectionProtocol = Protocol.Tcp
  30.             }
  31.         );
  32.     }
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top