Advertisement
hejmus

Untitled

Nov 10th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.Remoting.Messaging;
  5. using System.Web;
  6. using EAbs.Common.DB;
  7.  
  8. namespace EAbs.Web
  9. {
  10.     public static class UnitOfWorkStore
  11.     {
  12.         public static object GetData(string key)
  13.         {
  14.             //if (HttpContext.Current != null)
  15.                 return HttpContext.Current.Items[key];
  16.             //return CallContext.GetData(key);
  17.         }
  18.  
  19.         public static void SetData(string key, object data)
  20.         {
  21.             //if (HttpContext.Current != null)
  22.                 HttpContext.Current.Items[key] = data;
  23.             //else
  24.             //    CallContext.SetData(key, data);
  25.         }
  26.     }
  27.  
  28.     public class DBContextWrapper
  29.     {
  30.         private static readonly string UOW_INSTANCE_KEY = "ConfigContext_Instance";
  31.         private static readonly object _objSync = new object();
  32.  
  33.         private readonly ConfigContext _context;
  34.  
  35.         private DBContextWrapper()
  36.         {
  37.             _context = new ConfigContext();
  38.         }
  39.  
  40.         public ConfigContext Context
  41.         {
  42.             get { return _context; }
  43.         }
  44.  
  45.         public static DBContextWrapper Instance
  46.         {
  47.             get
  48.             {
  49.                 object instance = UnitOfWorkStore.GetData(UOW_INSTANCE_KEY);
  50.                 if (instance == null)
  51.                 {
  52.                     lock (_objSync)
  53.                     {
  54.                         if (instance == null)
  55.                         {
  56.                             instance = new DBContextWrapper();
  57.                             UnitOfWorkStore.SetData(UOW_INSTANCE_KEY, instance);
  58.                         }
  59.                     }
  60.                 }
  61.                 return (DBContextWrapper)instance;
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement