Advertisement
Guest User

ThreadContext

a guest
May 23rd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1.    public static class AlbatrossContext
  2.     {
  3.         [ThreadStatic]
  4.         private static ISimpleMessageSender<string> _output;
  5.  
  6.         public static ISimpleMessageSender<string> Output
  7.         {
  8.             get
  9.             {
  10.                 if (_output == null)
  11.                 {
  12.                     _output = SimpleMessageSender.ConsoleLogger("");
  13.                 }
  14.                 return _output;
  15.             }
  16.         }
  17.  
  18.  
  19.         public static IDisposable SetOutput(ISimpleMessageSender<string> newOutput)
  20.         {
  21.             var temp = _output;
  22.             _output = newOutput;
  23.  
  24.             return Disposable.Create(
  25.                 () =>
  26.                 {
  27.                     _output = temp;
  28.                 });
  29.         }
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement