示例#1
0
        private static ILifetimeScope FromHttpContext()
        {
            if (HttpContext.Current != null)
            {
                var scope = DisposableHttpContext.Current["scope"] as ILifetimeScope;
                if (scope == null)
                {
                    scope = ToHttpContext();
                }
                else
                {
                    scope = new LifeTimeScopeProxy(scope);
                    try
                    {
                        scope.Resolve <IDbManager>();
                    }
                    catch (ObjectDisposedException e)
                    {
                        Logger.Error("FromHttpContext ObjectDisposedException", e);
                        scope = ToHttpContext();
                    }
                }

                return(scope);
            }

            return(Builder.BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag));
        }
示例#2
0
        private static ILifetimeScope ToHttpContext()
        {
            var scope = Builder.BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag);
            var proxy = new LifeTimeScopeProxy(scope);

            DisposableHttpContext.Current["scope"] = scope;
            return(proxy);
        }