예제 #1
0
        private IDictionary GetItems()
        {
#if !NETSTANDARD1_6
            try
            {
                if (UseThreadStatic)
                {
                    return(RequestItems);
                }

                //Don't init CallContext on Main Thread which inits copies in Request threads
                if (!ServiceStackHost.IsReady())
                {
                    return(new Dictionary <object, object>());
                }

                if (System.Web.HttpContext.Current != null)
                {
                    return(System.Web.HttpContext.Current.Items);
                }

                return(CallContext.LogicalGetData(_key) as IDictionary);
            }
            catch (NotImplementedException)
            {
                //Fixed in Mono master: https://github.com/mono/mono/pull/817
                return(CallContext.GetData(_key) as IDictionary);
            }
#else
            return(AsyncRequestItems.Value);
#endif
        }
예제 #2
0
        /// <summary>
        /// Track any IDisposable's to dispose of at the end of the request in IAppHost.OnEndRequest()
        /// </summary>
        /// <param name="instance"></param>
        public void TrackDisposable(IDisposable instance)
        {
            if (!ServiceStackHost.IsReady())
            {
                return;
            }
            if (instance == null)
            {
                return;
            }
            if (instance is IService)
            {
                return;                       //IService's are already disposed right after they've been executed
            }
            DisposableTracker dispsableTracker = null;

            if (!Items.Contains(DisposableTracker.HashId))
            {
                Items[DisposableTracker.HashId] = dispsableTracker = new DisposableTracker();
            }
            if (dispsableTracker == null)
            {
                dispsableTracker = (DisposableTracker)Items[DisposableTracker.HashId];
            }
            dispsableTracker.Add(instance);
        }
예제 #3
0
        /// <summary>
        /// Release currently registered dependencies for this request
        /// </summary>
        /// <returns>true if any dependencies were released</returns>
        public bool ReleaseDisposables()
        {
            if (!ServiceStackHost.IsReady())
            {
                return(false);
            }
            if (!ServiceStackHost.Instance.Config.DisposeDependenciesAfterUse)
            {
                return(false);
            }

            var ctxItems    = Instance.Items;
            var disposables = ctxItems[DisposableTracker.HashId] as DisposableTracker;

            if (disposables != null)
            {
                disposables.Dispose();
                ctxItems.Remove(DisposableTracker.HashId);
                return(true);
            }

            return(false);
        }
예제 #4
0
        private IDictionary GetItems()
        {
            try
            {
                if (UseThreadStatic)
                {
                    return(RequestItems);
                }

                //Don't init CallContext on Main Thread which inits copies in Request threads
                if (!ServiceStackHost.IsReady())
                {
                    return(new Dictionary <object, object>());
                }

                return(CallContext.LogicalGetData(_key) as IDictionary);
            }
            catch (NotImplementedException)
            {
                //Fixed in Mono master: https://github.com/mono/mono/pull/817
                return(CallContext.GetData(_key) as IDictionary);
            }
        }