Exemplo n.º 1
0
        public static void ClearCurrent()
        {
            WebContext context = Current;

            if (HttpContext.Current != null)
            {
                HttpContext.Current.Items.Remove(CONTEXT_NAME);
            }
            else
            {
                Thread.FreeNamedDataSlot(CONTEXT_NAME);
            }
            if (context != null)
            {
                context.Cleanup();
            }
        }
Exemplo n.º 2
0
        public static void InitializeCurrent(IUnityContainer container, Action <IUnityContainer> register = null)
        {
            if (Current == null)
            {
                var childContainer = container.CreateChildContainer();
                if (register != null)
                {
                    register(childContainer);
                }
                WebContext context = new WebContext(childContainer);

                // store appropriately for the setting
                if (HttpContext.Current != null)
                {
                    HttpContext.Current.Items[CONTEXT_NAME] = context;
                }
                else
                {
                    LocalDataStoreSlot slot = Thread.GetNamedDataSlot(CONTEXT_NAME);
                    Thread.SetData(slot, context);
                }
            }
        }